Remove JDK 9 workarounds etc

See gh-17778
This commit is contained in:
Juergen Hoeller
2021-09-17 08:58:19 +02:00
parent e0a4b05142
commit b74e93807e
15 changed files with 36 additions and 77 deletions

View File

@@ -260,7 +260,7 @@ public class ReflectUtils {
return newInstance(getConstructor(type, parameterTypes), args);
}
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static Object newInstance(final Constructor cstruct, final Object[] args) {
boolean flag = cstruct.isAccessible();
try {
@@ -439,7 +439,7 @@ public class ReflectUtils {
return defineClass(className, b, loader, protectionDomain, null);
}
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static Class defineClass(String className, byte[] b, ClassLoader loader,
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {

View File

@@ -5,6 +5,6 @@
*
* <p>As this repackaging happens at the class file level, sources
* and javadocs are not available here... except for a few files
* that have been patched for Spring's purposes on JDK 9/10/11.
* that have been patched for Spring's purposes on JDK 9-17.
*/
package org.springframework.cglib.core;

View File

@@ -5,6 +5,6 @@
*
* <p>As this repackaging happens at the class file level, sources
* and javadocs are not available here... except for a few files
* that have been patched for Spring's purposes on JDK 9/10/11.
* that have been patched for Spring's purposes on JDK 9-17.
*/
package org.springframework.cglib.proxy;

View File

@@ -16,17 +16,18 @@
package org.springframework.core;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;
import java.util.function.Function;
import kotlinx.coroutines.CompletableDeferredKt;
import kotlinx.coroutines.Deferred;
import org.reactivestreams.Publisher;
import reactor.adapter.JdkFlowAdapter;
import reactor.blockhound.BlockHound;
import reactor.blockhound.integration.BlockHoundIntegration;
import reactor.core.publisher.Flux;
@@ -36,7 +37,6 @@ import rx.RxReactiveStreams;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
/**
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from
@@ -350,28 +350,12 @@ public class ReactiveAdapterRegistry {
private static class ReactorJdkFlowAdapterRegistrar {
void registerAdapter(ReactiveAdapterRegistry registry) {
// TODO: remove reflection when build requires JDK 9+
try {
String publisherName = "java.util.concurrent.Flow.Publisher";
Class<?> publisherClass = ClassUtils.forName(publisherName, getClass().getClassLoader());
String adapterName = "reactor.adapter.JdkFlowAdapter";
Class<?> flowAdapterClass = ClassUtils.forName(adapterName, getClass().getClassLoader());
Method toFluxMethod = flowAdapterClass.getMethod("flowPublisherToFlux", publisherClass);
Method toFlowMethod = flowAdapterClass.getMethod("publisherToFlowPublisher", Publisher.class);
Object emptyFlow = ReflectionUtils.invokeMethod(toFlowMethod, null, Flux.empty());
registry.registerReactiveType(
ReactiveTypeDescriptor.multiValue(publisherClass, () -> emptyFlow),
source -> (Publisher<?>) ReflectionUtils.invokeMethod(toFluxMethod, null, source),
publisher -> ReflectionUtils.invokeMethod(toFlowMethod, null, publisher)
);
}
catch (Throwable ex) {
// Ignore
}
Flow.Publisher<?> emptyFlow = JdkFlowAdapter.publisherToFlowPublisher(Flux.empty());
registry.registerReactiveType(
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> emptyFlow),
source -> JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<?>) source),
JdkFlowAdapter::publisherToFlowPublisher
);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2021 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,7 +16,6 @@
package org.springframework.core.convert.support;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashSet;
@@ -122,10 +121,7 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
byteBuffer.put(bytes);
// Extra cast necessary for compiling on JDK 9 plus running on JDK 8, since
// otherwise the overridden ByteBuffer-returning rewind method would be chosen
// which isn't available on JDK 8.
return ((Buffer) byteBuffer).rewind();
return byteBuffer.rewind();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -19,7 +19,6 @@ package org.springframework.core.io.buffer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
@@ -333,18 +332,14 @@ public class DefaultDataBuffer implements DataBuffer {
public DefaultDataBuffer slice(int index, int length) {
checkIndex(index, length);
int oldPosition = this.byteBuffer.position();
// Explicit access via Buffer base type for compatibility
// with covariant return type on JDK 9's ByteBuffer...
Buffer buffer = this.byteBuffer;
try {
buffer.position(index);
this.byteBuffer.position(index);
ByteBuffer slice = this.byteBuffer.slice();
// Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer
slice.limit(length);
return new SlicedDefaultDataBuffer(slice, this.dataBufferFactory, length);
}
finally {
buffer.position(oldPosition);
this.byteBuffer.position(oldPosition);
}
}
@@ -358,11 +353,8 @@ public class DefaultDataBuffer implements DataBuffer {
checkIndex(index, length);
ByteBuffer duplicate = this.byteBuffer.duplicate();
// Explicit access via Buffer base type for compatibility
// with covariant return type on JDK 9's ByteBuffer...
Buffer buffer = duplicate;
buffer.position(index);
buffer.limit(index + length);
duplicate.position(index);
duplicate.limit(index + length);
return duplicate.slice();
}

View File

@@ -778,7 +778,7 @@ public abstract class ClassUtils {
* conflicting method signatures (or a similar constraint is violated)
* @see java.lang.reflect.Proxy#getProxyClass
*/
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static Class<?> createCompositeInterface(Class<?>[] interfaces, @Nullable ClassLoader classLoader) {
Assert.notEmpty(interfaces, "Interface array must not be empty");
return Proxy.getProxyClass(classLoader, interfaces);

View File

@@ -194,7 +194,7 @@ public abstract class ReflectionUtils {
* @param ctor the constructor to make accessible
* @see java.lang.reflect.Constructor#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static void makeAccessible(Constructor<?> ctor) {
if ((!Modifier.isPublic(ctor.getModifiers()) ||
!Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) {
@@ -563,7 +563,7 @@ public abstract class ReflectionUtils {
* @param method the method to make accessible
* @see java.lang.reflect.Method#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static void makeAccessible(Method method) {
if ((!Modifier.isPublic(method.getModifiers()) ||
!Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) {
@@ -775,7 +775,7 @@ public abstract class ReflectionUtils {
* @param field the field to make accessible
* @see java.lang.reflect.Field#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings("deprecation")
public static void makeAccessible(Field field) {
if ((!Modifier.isPublic(field.getModifiers()) ||
!Modifier.isPublic(field.getDeclaringClass().getModifiers()) ||

View File

@@ -251,7 +251,7 @@ class ObjectUtilsTests {
@Deprecated
void hashCodeWithDouble() {
double dbl = 9830.43;
int expected = (new Double(dbl)).hashCode();
int expected = Double.valueOf(dbl).hashCode();
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(expected);
}