Suppress deprecations for compiling on JDK 19/20

This commit is contained in:
Juergen Hoeller 2023-05-03 10:17:12 +02:00
parent 87942ed71d
commit 4db724984e
3 changed files with 19 additions and 15 deletions

View File

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

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -401,6 +401,7 @@ public final class ConcurrentLruCache<K, V> {
} }
} }
@SuppressWarnings("deprecation") // for Thread.getId() on JDK 19
private static int getBufferIndex() { private static int getBufferIndex() {
return ((int) Thread.currentThread().getId()) & BUFFERS_MASK; return ((int) Thread.currentThread().getId()) & BUFFERS_MASK;
} }
@ -415,6 +416,7 @@ public final class ConcurrentLruCache<K, V> {
return (pending < MAX_PENDING_OPERATIONS); return (pending < MAX_PENDING_OPERATIONS);
} }
@SuppressWarnings("deprecation") // for Thread.getId() on JDK 19
void drain() { void drain() {
final int start = (int) Thread.currentThread().getId(); final int start = (int) Thread.currentThread().getId();
final int end = start + BUFFER_COUNT; final int end = start + BUFFER_COUNT;

View File

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