diff --git a/build/parents/build/pom.xml b/build/parents/build/pom.xml index 6147ff2aba5..51c1c4e75bd 100644 --- a/build/parents/build/pom.xml +++ b/build/parents/build/pom.xml @@ -1018,6 +1018,10 @@ jdk-deprecated-16 jdk-deprecated-17 jdk-deprecated-18 + jdk-deprecated-19 + jdk-deprecated-20 + jdk-deprecated-21 + jdk-deprecated-22 jdk-internal-1.8 jdk-internal-9 @@ -1030,6 +1034,10 @@ jdk-internal-16 jdk-internal-17 jdk-internal-18 + jdk-internal-19 + jdk-internal-20 + jdk-internal-21 + jdk-internal-22 diff --git a/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/DefaultResourceResolver.java b/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/DefaultResourceResolver.java index 2158420260e..5bf81af1ce6 100644 --- a/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/DefaultResourceResolver.java +++ b/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/DefaultResourceResolver.java @@ -9,6 +9,8 @@ import java.io.InputStream; import java.net.URL; +import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis; + /** * Default implementation of {@code ClassResolver} relying on an {@link AggregatedClassLoader}. * @@ -27,6 +29,8 @@ private DefaultResourceResolver(AggregatedClassLoader aggregatedClassLoader) { } @Override + @SuppressForbiddenApis(reason = "URL constructors are deprecated in JDK 20+ in favor of using URI.toURL()," + + " but we want to preserve backward compatibility for now (see below).") public InputStream locateResourceStream(String name) { try { final InputStream stream = aggregatedClassLoader.getResourceAsStream( name ); @@ -44,6 +48,8 @@ public InputStream locateResourceStream(String name) { try { @SuppressWarnings("deprecation") // TODO: HSEARCH-4765 address the URL -> URI constructor change once the URLClassLoader stops using the URL constructor + // Main problem: would URI.create(stripped).toURL() fail, since `stripped` seems to be a relative URL? + // Do we even have test coverage for this line? InputStream resourceStream = new URL( stripped ).openStream(); return resourceStream; } diff --git a/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/testsupport/types/JavaNetURLPropertyTypeDescriptor.java b/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/testsupport/types/JavaNetURLPropertyTypeDescriptor.java index afb2332a3f6..ed07c2e1813 100644 --- a/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/testsupport/types/JavaNetURLPropertyTypeDescriptor.java +++ b/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/testsupport/types/JavaNetURLPropertyTypeDescriptor.java @@ -19,6 +19,7 @@ import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; +import org.hibernate.search.util.impl.test.annotation.SuppressForbiddenApis; public class JavaNetURLPropertyTypeDescriptor extends PropertyTypeDescriptor { @@ -156,11 +157,10 @@ private static URL url(String spec) { } } - // TODO: HSEARCH-4765 To be removed when URL constructor is removed (JDK 20+). We keep it for now as users might still be using - // this constructor and we want to test such scenario + @SuppressForbiddenApis(reason = "We want to test 'new URL(...)' even in JDK 20+ where it's deprecated") private static URL urlAsNewUrl(String spec) { try { - @SuppressWarnings("deprecation") + @SuppressWarnings("deprecation") // We want to test 'new URL(...)' even in JDK 20+ where it's deprecated URL url = new URL( spec ); return url; } diff --git a/util/common/src/main/java/org/hibernate/search/util/common/jar/impl/CodeSource.java b/util/common/src/main/java/org/hibernate/search/util/common/jar/impl/CodeSource.java index d90d57ea102..b8a96b9bc3e 100644 --- a/util/common/src/main/java/org/hibernate/search/util/common/jar/impl/CodeSource.java +++ b/util/common/src/main/java/org/hibernate/search/util/common/jar/impl/CodeSource.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.function.BiFunction; +import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis; import org.hibernate.search.util.common.impl.Closer; import org.hibernate.search.util.common.impl.SuppressingCloser; import org.hibernate.search.util.common.impl.Throwables; @@ -77,6 +78,8 @@ class CodeSource implements Closeable { this.codeSourceLocation = codeSourceLocation; } + @SuppressForbiddenApis(reason = "URL constructors are deprecated in JDK 20+ in favor of using URI.toURL()," + + " but we need to start from URLs (not URIs) coming from java.security.CodeSource.") public InputStream readOrNull(String resourcePathString) throws IOException { Throwable exception = null;