Browse Source

Suppress deprecations for compiling on JDK 19/20

pull/30419/head
Juergen Hoeller 2 years ago
parent
commit
4db724984e
  1. 15
      spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java
  2. 4
      spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java
  3. 15
      spring-core/src/main/java/org/springframework/util/StringUtils.java

15
spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java

@ -85,15 +85,15 @@ public class DynamicClassLoader extends ClassLoader { @@ -85,15 +85,15 @@ public class DynamicClassLoader extends ClassLoader {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] bytes = findClassBytes(name);
if (bytes != null) {
return defineClass(name, bytes);
}
return super.findClass(name);
Class<?> clazz = defineClass(name, findClassBytes(name));
return (clazz != null ? clazz : super.findClass(name));
}
private Class<?> defineClass(String name, byte[] bytes) {
@Nullable
private Class<?> defineClass(String name, @Nullable byte[] bytes) {
if (bytes == null) {
return null;
}
if (this.defineClassMethod != null) {
return (Class<?>) ReflectionUtils.invokeMethod(this.defineClassMethod,
getParent(), name, bytes, 0, bytes.length);
@ -142,6 +142,7 @@ public class DynamicClassLoader extends ClassLoader { @@ -142,6 +142,7 @@ public class DynamicClassLoader extends ClassLoader {
return (dynamicClassFile != null) ? dynamicClassFile.getBytes() : null;
}
@SuppressWarnings("deprecation") // on JDK 20
private URL createResourceUrl(String name, Supplier<byte[]> bytesSupplier) {
try {
return new URL(null, "resource:///" + name,

4
spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@ -401,6 +401,7 @@ public final class ConcurrentLruCache<K, V> { @@ -401,6 +401,7 @@ public final class ConcurrentLruCache<K, V> {
}
}
@SuppressWarnings("deprecation") // for Thread.getId() on JDK 19
private static int getBufferIndex() {
return ((int) Thread.currentThread().getId()) & BUFFERS_MASK;
}
@ -415,6 +416,7 @@ public final class ConcurrentLruCache<K, V> { @@ -415,6 +416,7 @@ public final class ConcurrentLruCache<K, V> {
return (pending < MAX_PENDING_OPERATIONS);
}
@SuppressWarnings("deprecation") // for Thread.getId() on JDK 19
void drain() {
final int start = (int) Thread.currentThread().getId();
final int end = start + BUFFER_COUNT;

15
spring-core/src/main/java/org/springframework/util/StringUtils.java

@ -868,6 +868,7 @@ public abstract class StringUtils { @@ -868,6 +868,7 @@ public abstract class StringUtils {
* @return a corresponding {@code Locale} instance, or {@code null} if none
* @throws IllegalArgumentException in case of an invalid locale specification
*/
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
@Nullable
public static Locale parseLocaleString(String localeString) {
if (localeString.equals("")) {
@ -877,25 +878,25 @@ public abstract class StringUtils { @@ -877,25 +878,25 @@ public abstract class StringUtils {
if (!localeString.contains("_") && localeString.contains(" ")) {
delimiter = " ";
}
final String[] tokens = localeString.split(delimiter, -1);
String[] tokens = localeString.split(delimiter, -1);
if (tokens.length == 1) {
final String language = tokens[0];
String language = tokens[0];
validateLocalePart(language);
return new Locale(language);
}
else if (tokens.length == 2) {
final String language = tokens[0];
String language = tokens[0];
validateLocalePart(language);
final String country = tokens[1];
String country = tokens[1];
validateLocalePart(country);
return new Locale(language, country);
}
else if (tokens.length > 2) {
final String language = tokens[0];
String language = tokens[0];
validateLocalePart(language);
final String country = tokens[1];
String country = tokens[1];
validateLocalePart(country);
final String variant = Arrays.stream(tokens).skip(2).collect(Collectors.joining(delimiter));
String variant = Arrays.stream(tokens).skip(2).collect(Collectors.joining(delimiter));
return new Locale(language, country, variant);
}
throw new IllegalArgumentException("Invalid locale format: '" + localeString + "'");

Loading…
Cancel
Save