diff --git a/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java index 3bb8759a97b..72c07672344 100644 --- a/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.util.ClassUtils; + /** * Default implementation of the {@link ParameterNameDiscoverer} strategy interface, * using the Java 8 standard reflection mechanism (if available), and falling back @@ -31,8 +33,8 @@ package org.springframework.core; */ public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer { - private static final boolean standardReflectionAvailable = - (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_18); + private static final boolean standardReflectionAvailable = ClassUtils.isPresent( + "java.lang.reflect.Executable", DefaultParameterNameDiscoverer.class.getClassLoader()); public DefaultParameterNameDiscoverer() { diff --git a/spring-core/src/main/java/org/springframework/core/JdkVersion.java b/spring-core/src/main/java/org/springframework/core/JdkVersion.java index 06da1f27220..2f359b9b036 100644 --- a/spring-core/src/main/java/org/springframework/core/JdkVersion.java +++ b/spring-core/src/main/java/org/springframework/core/JdkVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -27,7 +27,10 @@ package org.springframework.core; * @author Juergen Hoeller * @author Rick Evans * @author Sam Brannen + * @deprecated as of Spring 4.2.1, in favor of direct checks for the desired + * JDK API variants via reflection */ +@Deprecated public abstract class JdkVersion { /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java index f0347bb5774..355009656d7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -22,7 +22,6 @@ import javax.sql.rowset.CachedRowSet; import javax.sql.rowset.RowSetFactory; import javax.sql.rowset.RowSetProvider; -import org.springframework.core.JdkVersion; import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.lang.UsesJava7; @@ -34,8 +33,8 @@ import org.springframework.util.ClassUtils; * *

The default implementation uses a standard JDBC CachedRowSet underneath. * This means that JDBC RowSet support needs to be available at runtime: - * by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 5 and 6, - * or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7 / JDBC 4.1. + * by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 6, + * or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7+ / JDBC 4.1+. * * @author Juergen Hoeller * @since 1.2 @@ -49,12 +48,13 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor= JdkVersion.JAVA_17) { - // using JDBC 4.1 RowSetProvider + if (ClassUtils.isPresent("javax.sql.rowset.RowSetProvider", + SqlRowSetResultSetExtractor.class.getClassLoader())) { + // using JDBC 4.1 RowSetProvider, available on JDK 7+ cachedRowSetFactory = new StandardCachedRowSetFactory(); } else { - // JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl + // JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl on JDK 6 cachedRowSetFactory = new SunCachedRowSetFactory(); } } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index 1164f122614..88c030a1e89 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -80,7 +80,6 @@ import org.xml.sax.helpers.XMLReaderFactory; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.core.JdkVersion; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.io.Resource; import org.springframework.oxm.GenericMarshaller; @@ -577,27 +576,28 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi } @Override + @SuppressWarnings("deprecation") public boolean supports(Type genericType) { if (genericType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericType; if (JAXBElement.class == parameterizedType.getRawType() && parameterizedType.getActualTypeArguments().length == 1) { + boolean isJdk6 = (org.springframework.core.JdkVersion.getMajorJavaVersion() <= org.springframework.core.JdkVersion.JAVA_16); Type typeArgument = parameterizedType.getActualTypeArguments()[0]; if (typeArgument instanceof Class) { Class classArgument = (Class) typeArgument; - if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_17 && classArgument.isArray()) { - return classArgument.getComponentType().equals(Byte.TYPE); - } - else { + if (isJdk6 && classArgument.isArray()) { return (isPrimitiveWrapper(classArgument) || isStandardClass(classArgument) || supportsInternal(classArgument, false)); } + else { + return (classArgument.getComponentType() == Byte.TYPE); + } } - else if (JdkVersion.getMajorJavaVersion() <= JdkVersion.JAVA_16 && - typeArgument instanceof GenericArrayType) { + else if (isJdk6 && typeArgument instanceof GenericArrayType) { // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 GenericArrayType arrayType = (GenericArrayType) typeArgument; - return arrayType.getGenericComponentType().equals(Byte.TYPE); + return (arrayType.getGenericComponentType() == Byte.TYPE); } } }