Skip to content

Commit b74e938

Browse files
committed
Remove JDK 9 workarounds etc
See gh-17778
1 parent e0a4b05 commit b74e938

File tree

15 files changed

+36
-77
lines changed

15 files changed

+36
-77
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.util.Assert;
3434
import org.springframework.util.ClassUtils;
3535
import org.springframework.util.ObjectUtils;
36-
import org.springframework.util.ReflectionUtils;
3736

3837
/**
3938
* Utility methods for AOP proxy factories.
@@ -48,11 +47,6 @@
4847
*/
4948
public abstract class AopProxyUtils {
5049

51-
// JDK 17 Class.isSealed() method available?
52-
@Nullable
53-
private static final Method isSealedMethod = ClassUtils.getMethodIfAvailable(Class.class, "isSealed");
54-
55-
5650
/**
5751
* Obtain the singleton target object behind the given proxy, if any.
5852
* @param candidate the (potential) proxy to check
@@ -142,7 +136,7 @@ else if (Proxy.isProxyClass(targetClass)) {
142136
List<Class<?>> proxiedInterfaces = new ArrayList<>(specifiedInterfaces.length + 3);
143137
for (Class<?> ifc : specifiedInterfaces) {
144138
// Only non-sealed interfaces are actually eligible for JDK proxying (on JDK 17)
145-
if (isSealedMethod == null || Boolean.FALSE.equals(ReflectionUtils.invokeMethod(isSealedMethod, ifc))) {
139+
if (!ifc.isSealed()) {
146140
proxiedInterfaces.add(ifc);
147141
}
148142
}

spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public static Object newInstance(Class type, Class[] parameterTypes, Object[] ar
260260
return newInstance(getConstructor(type, parameterTypes), args);
261261
}
262262

263-
@SuppressWarnings("deprecation") // on JDK 9
263+
@SuppressWarnings("deprecation")
264264
public static Object newInstance(final Constructor cstruct, final Object[] args) {
265265
boolean flag = cstruct.isAccessible();
266266
try {
@@ -439,7 +439,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
439439
return defineClass(className, b, loader, protectionDomain, null);
440440
}
441441

442-
@SuppressWarnings("deprecation") // on JDK 9
442+
@SuppressWarnings("deprecation")
443443
public static Class defineClass(String className, byte[] b, ClassLoader loader,
444444
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
445445

spring-core/src/main/java/org/springframework/cglib/core/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
*
66
* <p>As this repackaging happens at the class file level, sources
77
* and javadocs are not available here... except for a few files
8-
* that have been patched for Spring's purposes on JDK 9/10/11.
8+
* that have been patched for Spring's purposes on JDK 9-17.
99
*/
1010
package org.springframework.cglib.core;

spring-core/src/main/java/org/springframework/cglib/proxy/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
*
66
* <p>As this repackaging happens at the class file level, sources
77
* and javadocs are not available here... except for a few files
8-
* that have been patched for Spring's purposes on JDK 9/10/11.
8+
* that have been patched for Spring's purposes on JDK 9-17.
99
*/
1010
package org.springframework.cglib.proxy;

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
package org.springframework.core;
1818

19-
import java.lang.reflect.Method;
2019
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.Optional;
2322
import java.util.concurrent.CompletableFuture;
2423
import java.util.concurrent.CompletionStage;
24+
import java.util.concurrent.Flow;
2525
import java.util.function.Function;
2626

2727
import kotlinx.coroutines.CompletableDeferredKt;
2828
import kotlinx.coroutines.Deferred;
2929
import org.reactivestreams.Publisher;
30+
import reactor.adapter.JdkFlowAdapter;
3031
import reactor.blockhound.BlockHound;
3132
import reactor.blockhound.integration.BlockHoundIntegration;
3233
import reactor.core.publisher.Flux;
@@ -36,7 +37,6 @@
3637
import org.springframework.lang.Nullable;
3738
import org.springframework.util.ClassUtils;
3839
import org.springframework.util.ConcurrentReferenceHashMap;
39-
import org.springframework.util.ReflectionUtils;
4040

4141
/**
4242
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from
@@ -350,28 +350,12 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
350350
private static class ReactorJdkFlowAdapterRegistrar {
351351

352352
void registerAdapter(ReactiveAdapterRegistry registry) {
353-
// TODO: remove reflection when build requires JDK 9+
354-
355-
try {
356-
String publisherName = "java.util.concurrent.Flow.Publisher";
357-
Class<?> publisherClass = ClassUtils.forName(publisherName, getClass().getClassLoader());
358-
359-
String adapterName = "reactor.adapter.JdkFlowAdapter";
360-
Class<?> flowAdapterClass = ClassUtils.forName(adapterName, getClass().getClassLoader());
361-
362-
Method toFluxMethod = flowAdapterClass.getMethod("flowPublisherToFlux", publisherClass);
363-
Method toFlowMethod = flowAdapterClass.getMethod("publisherToFlowPublisher", Publisher.class);
364-
Object emptyFlow = ReflectionUtils.invokeMethod(toFlowMethod, null, Flux.empty());
365-
366-
registry.registerReactiveType(
367-
ReactiveTypeDescriptor.multiValue(publisherClass, () -> emptyFlow),
368-
source -> (Publisher<?>) ReflectionUtils.invokeMethod(toFluxMethod, null, source),
369-
publisher -> ReflectionUtils.invokeMethod(toFlowMethod, null, publisher)
370-
);
371-
}
372-
catch (Throwable ex) {
373-
// Ignore
374-
}
353+
Flow.Publisher<?> emptyFlow = JdkFlowAdapter.publisherToFlowPublisher(Flux.empty());
354+
registry.registerReactiveType(
355+
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> emptyFlow),
356+
source -> JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<?>) source),
357+
JdkFlowAdapter::publisherToFlowPublisher
358+
);
375359
}
376360
}
377361

spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 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,7 +16,6 @@
1616

1717
package org.springframework.core.convert.support;
1818

19-
import java.nio.Buffer;
2019
import java.nio.ByteBuffer;
2120
import java.util.Collections;
2221
import java.util.HashSet;
@@ -122,10 +121,7 @@ private Object convertToByteBuffer(@Nullable Object source, TypeDescriptor sourc
122121
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
123122
byteBuffer.put(bytes);
124123

125-
// Extra cast necessary for compiling on JDK 9 plus running on JDK 8, since
126-
// otherwise the overridden ByteBuffer-returning rewind method would be chosen
127-
// which isn't available on JDK 8.
128-
return ((Buffer) byteBuffer).rewind();
124+
return byteBuffer.rewind();
129125
}
130126

131127
}

spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.OutputStream;
22-
import java.nio.Buffer;
2322
import java.nio.ByteBuffer;
2423
import java.nio.charset.Charset;
2524
import java.util.Arrays;
@@ -333,18 +332,14 @@ private void write(ByteBuffer source) {
333332
public DefaultDataBuffer slice(int index, int length) {
334333
checkIndex(index, length);
335334
int oldPosition = this.byteBuffer.position();
336-
// Explicit access via Buffer base type for compatibility
337-
// with covariant return type on JDK 9's ByteBuffer...
338-
Buffer buffer = this.byteBuffer;
339335
try {
340-
buffer.position(index);
336+
this.byteBuffer.position(index);
341337
ByteBuffer slice = this.byteBuffer.slice();
342-
// Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer
343338
slice.limit(length);
344339
return new SlicedDefaultDataBuffer(slice, this.dataBufferFactory, length);
345340
}
346341
finally {
347-
buffer.position(oldPosition);
342+
this.byteBuffer.position(oldPosition);
348343
}
349344
}
350345

@@ -358,11 +353,8 @@ public ByteBuffer asByteBuffer(int index, int length) {
358353
checkIndex(index, length);
359354

360355
ByteBuffer duplicate = this.byteBuffer.duplicate();
361-
// Explicit access via Buffer base type for compatibility
362-
// with covariant return type on JDK 9's ByteBuffer...
363-
Buffer buffer = duplicate;
364-
buffer.position(index);
365-
buffer.limit(index + length);
356+
duplicate.position(index);
357+
duplicate.limit(index + length);
366358
return duplicate.slice();
367359
}
368360

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, @Nulla
778778
* conflicting method signatures (or a similar constraint is violated)
779779
* @see java.lang.reflect.Proxy#getProxyClass
780780
*/
781-
@SuppressWarnings("deprecation") // on JDK 9
781+
@SuppressWarnings("deprecation")
782782
public static Class<?> createCompositeInterface(Class<?>[] interfaces, @Nullable ClassLoader classLoader) {
783783
Assert.notEmpty(interfaces, "Interface array must not be empty");
784784
return Proxy.getProxyClass(classLoader, interfaces);

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public static <T> Constructor<T> accessibleConstructor(Class<T> clazz, Class<?>.
194194
* @param ctor the constructor to make accessible
195195
* @see java.lang.reflect.Constructor#setAccessible
196196
*/
197-
@SuppressWarnings("deprecation") // on JDK 9
197+
@SuppressWarnings("deprecation")
198198
public static void makeAccessible(Constructor<?> ctor) {
199199
if ((!Modifier.isPublic(ctor.getModifiers()) ||
200200
!Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) {
@@ -563,7 +563,7 @@ public static boolean isCglibRenamedMethod(Method renamedMethod) {
563563
* @param method the method to make accessible
564564
* @see java.lang.reflect.Method#setAccessible
565565
*/
566-
@SuppressWarnings("deprecation") // on JDK 9
566+
@SuppressWarnings("deprecation")
567567
public static void makeAccessible(Method method) {
568568
if ((!Modifier.isPublic(method.getModifiers()) ||
569569
!Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) {
@@ -775,7 +775,7 @@ public static boolean isPublicStaticFinal(Field field) {
775775
* @param field the field to make accessible
776776
* @see java.lang.reflect.Field#setAccessible
777777
*/
778-
@SuppressWarnings("deprecation") // on JDK 9
778+
@SuppressWarnings("deprecation")
779779
public static void makeAccessible(Field field) {
780780
if ((!Modifier.isPublic(field.getModifiers()) ||
781781
!Modifier.isPublic(field.getDeclaringClass().getModifiers()) ||

spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void hashCodeWithBooleanTrue() {
251251
@Deprecated
252252
void hashCodeWithDouble() {
253253
double dbl = 9830.43;
254-
int expected = (new Double(dbl)).hashCode();
254+
int expected = Double.valueOf(dbl).hashCode();
255255
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(expected);
256256
}
257257

spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ else if (found) {
681681
setSourceMethodName(sourceMethodName);
682682
}
683683

684-
@SuppressWarnings("deprecation") // setMillis is deprecated in JDK 9
684+
@SuppressWarnings("deprecation")
685685
protected Object writeReplace() {
686686
LogRecord serialized = new LogRecord(getLevel(), getMessage());
687687
serialized.setLoggerName(getLoggerName());

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -17,7 +17,6 @@
1717
package org.springframework.messaging.simp.stomp;
1818

1919
import java.io.ByteArrayOutputStream;
20-
import java.nio.Buffer;
2120
import java.nio.ByteBuffer;
2221
import java.nio.charset.StandardCharsets;
2322
import java.util.ArrayList;
@@ -134,11 +133,7 @@ public List<Message<byte[]>> decode(ByteBuffer byteBuffer,
134133
private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap<String, String> headers) {
135134
Message<byte[]> decodedMessage = null;
136135
skipEol(byteBuffer);
137-
138-
// Explicit mark/reset access via Buffer base type for compatibility
139-
// with covariant return type on JDK 9's ByteBuffer...
140-
Buffer buffer = byteBuffer;
141-
buffer.mark();
136+
byteBuffer.mark();
142137

143138
String command = readCommand(byteBuffer);
144139
if (command.length() > 0) {
@@ -176,7 +171,7 @@ private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValu
176171
headers.putAll(map);
177172
}
178173
}
179-
buffer.reset();
174+
byteBuffer.reset();
180175
}
181176
}
182177
else {
@@ -357,8 +352,7 @@ else if (b == '\r') {
357352
throw new StompConversionException("'\\r' must be followed by '\\n'");
358353
}
359354
}
360-
// Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer
361-
((Buffer) byteBuffer).position(byteBuffer.position() - 1);
355+
byteBuffer.position(byteBuffer.position() - 1);
362356
}
363357
return false;
364358
}

spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -189,7 +189,7 @@ protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
189189
* @return the XMLReader
190190
* @throws SAXException if thrown by JAXP methods
191191
*/
192-
@SuppressWarnings("deprecation") // on JDK 9
192+
@SuppressWarnings("deprecation")
193193
protected XMLReader createXmlReader() throws SAXException {
194194
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
195195
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());

spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -122,7 +122,6 @@ public int getMaxInMemorySize() {
122122

123123

124124
@Override
125-
@SuppressWarnings({"rawtypes", "unchecked", "cast"}) // XMLEventReader is Iterator<Object> on JDK 9
126125
public Flux<XMLEvent> decode(Publisher<DataBuffer> input, ResolvableType elementType,
127126
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
128127

@@ -137,7 +136,7 @@ public Flux<XMLEvent> decode(Publisher<DataBuffer> input, ResolvableType element
137136
.flatMapIterable(buffer -> {
138137
try {
139138
InputStream is = buffer.asInputStream();
140-
Iterator eventReader = inputFactory.createXMLEventReader(is);
139+
Iterator<Object> eventReader = inputFactory.createXMLEventReader(is);
141140
List<XMLEvent> result = new ArrayList<>();
142141
eventReader.forEachRemaining(event -> result.add((XMLEvent) event));
143142
return result;

spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -197,7 +197,7 @@ private DOMSource readDOMSource(InputStream body, HttpInputMessage inputMessage)
197197
}
198198
}
199199

200-
@SuppressWarnings("deprecation") // on JDK 9
200+
@SuppressWarnings("deprecation")
201201
private SAXSource readSAXSource(InputStream body, HttpInputMessage inputMessage) throws IOException {
202202
try {
203203
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();

0 commit comments

Comments
 (0)