Browse Source

Deprecate JdkVersion (for optimistic compatibility with newer JDK generations)

Issue: SPR-13312
pull/853/merge
Juergen Hoeller 10 years ago
parent
commit
bec3b0fa1a
  1. 8
      spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java
  2. 5
      spring-core/src/main/java/org/springframework/core/JdkVersion.java
  3. 14
      spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java
  4. 16
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

8
spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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() {

5
spring-core/src/main/java/org/springframework/core/JdkVersion.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 {
/**

14
spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -34,8 +33,8 @@ import org.springframework.util.ClassUtils;
*
* <p>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<SqlRowSet @@ -49,12 +48,13 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
private static final CachedRowSetFactory cachedRowSetFactory;
static {
if (JdkVersion.getMajorJavaVersion() >= 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();
}
}

16
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -80,7 +80,6 @@ import org.xml.sax.helpers.XMLReaderFactory; @@ -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 @@ -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);
}
}
}

Loading…
Cancel
Save