Skip to content

Commit

Permalink
HSEARCH-5155 Add forbiddenapis checks for JDK 19 -> 22
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed May 22, 2024
1 parent ce46419 commit 5efb7b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions build/parents/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,10 @@
<bundledSignature>jdk-deprecated-16</bundledSignature>
<bundledSignature>jdk-deprecated-17</bundledSignature>
<bundledSignature>jdk-deprecated-18</bundledSignature>
<bundledSignature>jdk-deprecated-19</bundledSignature>
<bundledSignature>jdk-deprecated-20</bundledSignature>
<bundledSignature>jdk-deprecated-21</bundledSignature>
<bundledSignature>jdk-deprecated-22</bundledSignature>

<bundledSignature>jdk-internal-1.8</bundledSignature>
<bundledSignature>jdk-internal-9</bundledSignature>
Expand All @@ -1030,6 +1034,10 @@
<bundledSignature>jdk-internal-16</bundledSignature>
<bundledSignature>jdk-internal-17</bundledSignature>
<bundledSignature>jdk-internal-18</bundledSignature>
<bundledSignature>jdk-internal-19</bundledSignature>
<bundledSignature>jdk-internal-20</bundledSignature>
<bundledSignature>jdk-internal-21</bundledSignature>
<bundledSignature>jdk-internal-22</bundledSignature>
</bundledSignatures>
<signaturesArtifacts>
<signaturesArtifact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand All @@ -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 );
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<URL, String> {

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5efb7b9

Please sign in to comment.