Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Last active December 18, 2021 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotty3000/d9feec79a66f14c2360fee9b9a1b2852 to your computer and use it in GitHub Desktop.
Save rotty3000/d9feec79a66f14c2360fee9b9a1b2852 to your computer and use it in GitHub Desktop.
jdeps as ToolProvider exception on reuse
/*
The jdeps args used can be:
*/
jdeps0(
"--ignore-missing-deps",
"--no-recursive",
"--print-module-deps",
"--multi-release",
System.getProperty("java.specification.version"),
file.getAbsolutePath());
/* code that fails with `com.sun.tools.jdeps.MultiReleaseException` */
public static String jdeps0(String... args) {
try (final StringWriter stdout = new StringWriter();
final StringWriter stderr = new StringWriter();
final PrintWriter pwout = new PrintWriter(stdout);
final PrintWriter pwerr = new PrintWriter(stderr)) {
return (ToolProvider.findFirst("jdeps").orElseThrow().run(pwout, pwerr, args) == 0) ?
stdout.toString() :
"Error: ".concat(stderr.toString());
}
catch (Throwable t) {
t.printStackTrace();
return "Error: " + t.getMessage();
}
}
/* code that does not fail */
public static final Field field;
public static final Map<?,?> map;
static {
try {
Class<?> clazz = Class.forName("com.sun.tools.jdeps.VersionHelper");
field = clazz.getDeclaredField("nameToVersion");
field.setAccessible(true);
map = (Map<?,?>)field.get(null);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
public static String jdeps0(String... args) {
try (final StringWriter stdout = new StringWriter();
final StringWriter stderr = new StringWriter();
final PrintWriter pwout = new PrintWriter(stdout);
final PrintWriter pwerr = new PrintWriter(stderr)) {
return (ToolProvider.findFirst("jdeps").orElseThrow().run(pwout, pwerr, args) == 0) ?
stdout.toString() :
"Error: ".concat(stderr.toString());
}
catch (Throwable t) {
t.printStackTrace();
return "Error: " + t.getMessage();
}
finally {
map.clear();
}
}
java.lang.Error: java.util.concurrent.ExecutionException: com.sun.tools.jdeps.MultiReleaseException
at jdk.jdeps/com.sun.tools.jdeps.DependencyFinder.waitForTasksCompleted(DependencyFinder.java:271)
at jdk.jdeps/com.sun.tools.jdeps.DependencyFinder.parse(DependencyFinder.java:133)
at jdk.jdeps/com.sun.tools.jdeps.DepsAnalyzer.run(DepsAnalyzer.java:129)
at jdk.jdeps/com.sun.tools.jdeps.ModuleExportsAnalyzer.run(ModuleExportsAnalyzer.java:74)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask$ListModuleDeps.run(JdepsTask.java:1047)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:574)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
at jdk.jdeps/com.sun.tools.jdeps.Main.run(Main.java:64)
at jdk.jdeps/com.sun.tools.jdeps.Main$JDepsToolProvider.run(Main.java:73)
[snip]
Caused by: java.util.concurrent.ExecutionException: com.sun.tools.jdeps.MultiReleaseException
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at jdk.jdeps/com.sun.tools.jdeps.DependencyFinder.waitForTasksCompleted(DependencyFinder.java:267)
... 24 more
Caused by: com.sun.tools.jdeps.MultiReleaseException
at jdk.jdeps/com.sun.tools.jdeps.VersionHelper.add(VersionHelper.java:62)
at jdk.jdeps/com.sun.tools.jdeps.ClassFileReader$JarFileReader.readClassFile(ClassFileReader.java:360)
at jdk.jdeps/com.sun.tools.jdeps.ClassFileReader$JarFileIterator.hasNext(ClassFileReader.java:402)
at jdk.jdeps/com.sun.tools.jdeps.DependencyFinder.lambda$parse$5(DependencyFinder.java:179)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
--add-opens jdk.jdeps/com.sun.tools.jdeps=ALL-UNNAMED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment