Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix patched module resource lookup #793

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/io/github/classgraph/ClasspathElementModule.java
Expand Up @@ -183,6 +183,20 @@ ClassfileReader openClassfile() throws IOException {
return new ClassfileReader(open(), this);
}

@Override
public URI getURI() {
try {
ModuleReaderProxy localModuleReaderProxy = moduleReaderProxyRecycler.acquire();
try {
return localModuleReaderProxy.find(resourcePath);
} finally {
moduleReaderProxyRecycler.recycle(localModuleReaderProxy);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public InputStream open() throws IOException {
if (skipClasspathElement) {
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/io/github/classgraph/ModuleReaderProxy.java
Expand Up @@ -31,6 +31,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.List;

Expand Down Expand Up @@ -183,4 +184,27 @@ public void release(final ByteBuffer byteBuffer) {
reflectionUtils.invokeMethod(/* throwException = */ true, moduleReader, "release", ByteBuffer.class,
byteBuffer);
}
}

/**
* Use the proxied ModuleReader to find the named resource as a URI.
*
* @param path
* The path to the resource to open.
* @return A {@link URI} for the resource.
* @throws SecurityException
* If the module cannot be accessed.
*/
public URI find(final String path) {
final Object /* Optional<URI> */ optionalURI = reflectionUtils.invokeMethod(/* throwException = */ true, moduleReader, "find", String.class,
path);
if (optionalURI == null) {
throw new IllegalArgumentException("Got null result from ModuleReader#find(String)");
}
final URI uri = (URI) reflectionUtils.invokeMethod(/* throwException = */ true,
optionalURI, "get");
if (uri == null) {
throw new IllegalArgumentException("Got null result from ModuleReader#find(String).get()");
}
return uri;
}
}