On Fri, 16 Sep 2022 08:26:00 GMT, Matthias Baesken <mbaes...@openjdk.org> wrote:
> We noticed that with certain jar file input, jdeps runs into the following > exception, this happens with jdk11, 17 and 20. > > jdeps.exe --multi-release 11 --module-path . --inverse --package > com.sap.nw.performance.supa.client test.jar > > Inverse transitive dependences matching packages > [com.sap.nw.performance.supa.client] > Exception in thread "main" java.util.NoSuchElementException: No value present > at java.base/java.util.Optional.get(Optional.java:148) > at > jdk.jdeps/com.sun.tools.jdeps.InverseDepsAnalyzer.lambda$inverseDependences$2(InverseDepsAnalyzer.java:150) > at > java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) > at > java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) > at > java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) > at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) > at > java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) > at > java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) > at > java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) > > So an additional check might be a good idea. I created a reproducible test case attached in the JBS issue. This is caused by the optional dependency `requires static M;` which is not resolved in the runtime configuration even if it's observable. diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java index 5720fe7f60a..18ef9af3422 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java @@ -145,6 +145,9 @@ public class InverseDepsAnalyzer extends DepsAnalyzer { .forEach(m -> { builder.addNode(m); m.descriptor().requires().stream() + // filter "requires static" if the module is not resolved in the configuration + .filter(req -> !req.modifiers().contains(Requires.Modifier.STATIC) + || configuration.findModule(req.name()).isPresent()) .map(Requires::name) .map(configuration::findModule) // must be present .forEach(v -> builder.addEdge(v.get(), m)); ------------- PR: https://git.openjdk.org/jdk/pull/10300