Skip to content

Commit bec3b0f

Browse files
committed
Deprecate JdkVersion (for optimistic compatibility with newer JDK generations)
Issue: SPR-13312
1 parent e20b47c commit bec3b0f

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.core;
1818

19+
import org.springframework.util.ClassUtils;
20+
1921
/**
2022
* Default implementation of the {@link ParameterNameDiscoverer} strategy interface,
2123
* using the Java 8 standard reflection mechanism (if available), and falling back
@@ -31,8 +33,8 @@
3133
*/
3234
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
3335

34-
private static final boolean standardReflectionAvailable =
35-
(JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_18);
36+
private static final boolean standardReflectionAvailable = ClassUtils.isPresent(
37+
"java.lang.reflect.Executable", DefaultParameterNameDiscoverer.class.getClassLoader());
3638

3739

3840
public DefaultParameterNameDiscoverer() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,10 @@
2727
* @author Juergen Hoeller
2828
* @author Rick Evans
2929
* @author Sam Brannen
30+
* @deprecated as of Spring 4.2.1, in favor of direct checks for the desired
31+
* JDK API variants via reflection
3032
*/
33+
@Deprecated
3134
public abstract class JdkVersion {
3235

3336
/**

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
2222
import javax.sql.rowset.RowSetFactory;
2323
import javax.sql.rowset.RowSetProvider;
2424

25-
import org.springframework.core.JdkVersion;
2625
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
2726
import org.springframework.jdbc.support.rowset.SqlRowSet;
2827
import org.springframework.lang.UsesJava7;
@@ -34,8 +33,8 @@
3433
*
3534
* <p>The default implementation uses a standard JDBC CachedRowSet underneath.
3635
* This means that JDBC RowSet support needs to be available at runtime:
37-
* by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 5 and 6,
38-
* or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7 / JDBC 4.1.
36+
* by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 6,
37+
* or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7+ / JDBC 4.1+.
3938
*
4039
* @author Juergen Hoeller
4140
* @since 1.2
@@ -49,12 +48,13 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
4948
private static final CachedRowSetFactory cachedRowSetFactory;
5049

5150
static {
52-
if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_17) {
53-
// using JDBC 4.1 RowSetProvider
51+
if (ClassUtils.isPresent("javax.sql.rowset.RowSetProvider",
52+
SqlRowSetResultSetExtractor.class.getClassLoader())) {
53+
// using JDBC 4.1 RowSetProvider, available on JDK 7+
5454
cachedRowSetFactory = new StandardCachedRowSetFactory();
5555
}
5656
else {
57-
// JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl
57+
// JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl on JDK 6
5858
cachedRowSetFactory = new SunCachedRowSetFactory();
5959
}
6060
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080

8181
import org.springframework.beans.factory.BeanClassLoaderAware;
8282
import org.springframework.beans.factory.InitializingBean;
83-
import org.springframework.core.JdkVersion;
8483
import org.springframework.core.annotation.AnnotationUtils;
8584
import org.springframework.core.io.Resource;
8685
import org.springframework.oxm.GenericMarshaller;
@@ -577,27 +576,28 @@ public boolean supports(Class<?> clazz) {
577576
}
578577

579578
@Override
579+
@SuppressWarnings("deprecation")
580580
public boolean supports(Type genericType) {
581581
if (genericType instanceof ParameterizedType) {
582582
ParameterizedType parameterizedType = (ParameterizedType) genericType;
583583
if (JAXBElement.class == parameterizedType.getRawType() &&
584584
parameterizedType.getActualTypeArguments().length == 1) {
585+
boolean isJdk6 = (org.springframework.core.JdkVersion.getMajorJavaVersion() <= org.springframework.core.JdkVersion.JAVA_16);
585586
Type typeArgument = parameterizedType.getActualTypeArguments()[0];
586587
if (typeArgument instanceof Class) {
587588
Class<?> classArgument = (Class<?>) typeArgument;
588-
if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_17 && classArgument.isArray()) {
589-
return classArgument.getComponentType().equals(Byte.TYPE);
590-
}
591-
else {
589+
if (isJdk6 && classArgument.isArray()) {
592590
return (isPrimitiveWrapper(classArgument) || isStandardClass(classArgument) ||
593591
supportsInternal(classArgument, false));
594592
}
593+
else {
594+
return (classArgument.getComponentType() == Byte.TYPE);
595+
}
595596
}
596-
else if (JdkVersion.getMajorJavaVersion() <= JdkVersion.JAVA_16 &&
597-
typeArgument instanceof GenericArrayType) {
597+
else if (isJdk6 && typeArgument instanceof GenericArrayType) {
598598
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784
599599
GenericArrayType arrayType = (GenericArrayType) typeArgument;
600-
return arrayType.getGenericComponentType().equals(Byte.TYPE);
600+
return (arrayType.getGenericComponentType() == Byte.TYPE);
601601
}
602602
}
603603
}

0 commit comments

Comments
 (0)