-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Check for classpath alignment on LinkageErrors #4244
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
Conversation
The Launcher now checks for classpath alignment in case a LinkageError such as a ClassNotFoundError is thrown from one of the methods of the Launcher or TestEngine interfaces. If it finds unaligned versions, it wraps the LinkageError in a JUnitException with a message listing the detected versions and a link to the User Guide. Resolves #3935.
| assertEquals(1, result.exitCode()); | ||
| assertEquals("", result.stdErr()); | ||
| assertTrue(result.stdOutLines().contains("[INFO] BUILD FAILURE")); | ||
| assertThat(result.stdOut()) // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sample Maven output:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.325 s
[INFO] Finished at: 2025-01-12T17:47:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.2:test (default-test) on project maven-starter:
[ERROR]
[ERROR] See /tmp/junit-11800371830507414181/target/surefire-reports for the individual test results.
[ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] org.junit.platform.commons.JUnitException: The wrapped NoClassDefFoundError is likely caused by the versions of JUnit jars on the classpath/module path not being properly aligned.
[ERROR] Please ensure consistent versions are used (see https://junit.org/junit5/docs/5.12.0-SNAPSHOT/user-guide/#dependency-metadata).
[ERROR] The following versions were detected:
[ERROR] - org.junit.platform.commons: 1.11.4
[ERROR] - org.junit.platform.engine: 1.12.0-SNAPSHOT
[ERROR] - org.junit.platform.launcher: 1.12.0-SNAPSHOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "The following conflicting versions were detected"?
Out of curiosity, why does the link point to 5.12.0-SNAPSHOT instead of snapshot? Is that version pulled from a JAR manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why does the link point to
5.12.0-SNAPSHOTinstead ofsnapshot? Is that version pulled from a JAR manifest?
Never mind: I just noticed in the code that the latter is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "The following conflicting versions were detected"?
Done in d11a104
| Function<String, Package> packageLookup = name -> ReflectionSupport.findMethod(ClassLoader.class, | ||
| "getDefinedPackage", String.class) // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java 9+
| Function<String, Package> packageLookup = name -> ReflectionSupport.findMethod(ClassLoader.class, | ||
| "getDefinedPackage", String.class) // | ||
| .map(m -> (Package) ReflectionSupport.invokeMethod(m, classLoader, name)) // | ||
| .orElseGet(() -> getPackage(name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works for packages for which classes have already been loaded by the class loader and thus is likely to contain the conflicting JARs.
...tform-launcher/src/main/java/org/junit/platform/launcher/core/ClasspathAlignmentChecker.java
Show resolved
Hide resolved
7c2621b to
3461d16
Compare
sbrannen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only skimmed over the implementation and tests, but the resulting output looks good. 👍
Thanks, Marc
The Launcher now checks for classpath alignment in case a LinkageError
such as a ClassNotFoundError is thrown from one of the methods of the
Launcher or TestEngine interfaces. If it finds unaligned versions, it
wraps the LinkageError in a JUnitException with a message listing the
detected versions and a link to the User Guide.
Resolves #3935.