From b9ca0fb947b30ebbfec6e40732202c839936fe82 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 3 May 2013 17:28:58 +0200 Subject: [PATCH] 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). --- .../springframework/core/MethodParameter.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 28e9f90677..5ed09f139e 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -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"); * you may not use this file except in compliance with the License. @@ -162,18 +162,34 @@ public class MethodParameter { /** * Returns the wrapped member. - * @return the member + * @return the Method or Constructor as Member */ 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. - * @return the annotated element + * @return the Method or Constructor as AnnotatedElement */ 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; + } } /**