Compatibility of JDK 8 compiled reflection API usage with JDK <8 runtimes

Specifically, we need to avoid "... ? this.method : this.constructor" expressions since those potentially select java.lang.reflect.Executable (which is only available on JDK 8) as common type and hardcode this into the generated bytecode (which therefore becomes JDK 8 dependent).
This commit is contained in:
Juergen Hoeller 2013-05-03 17:28:58 +02:00
parent 255eab5bed
commit b9ca0fb947
1 changed files with 21 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -162,18 +162,34 @@ public class MethodParameter {
/** /**
* Returns the wrapped member. * Returns the wrapped member.
* @return the member * @return the Method or Constructor as Member
*/ */
private Member getMember() { private Member getMember() {
return this.method != null ? this.method : this.constructor; // NOTE: no ternary expression to retain JDK <8 compatibility even when using
// the JDK 8 compiler (potentially selecting java.lang.reflect.Executable
// as common type, with that new base class not available on older JDKs)
if (this.method != null) {
return this.method;
}
else {
return this.constructor;
}
} }
/** /**
* Returns the wrapped annotated element. * Returns the wrapped annotated element.
* @return the annotated element * @return the Method or Constructor as AnnotatedElement
*/ */
private AnnotatedElement getAnnotatedElement() { private AnnotatedElement getAnnotatedElement() {
return this.method != null ? this.method : this.constructor; // NOTE: no ternary expression to retain JDK <8 compatibility even when using
// the JDK 8 compiler (potentially selecting java.lang.reflect.Executable
// as common type, with that new base class not available on older JDKs)
if (this.method != null) {
return this.method;
}
else {
return this.constructor;
}
} }
/** /**