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

Show module version in stack trace #11447

Closed
Thihup opened this issue Dec 11, 2020 · 3 comments · Fixed by #11601
Closed

Show module version in stack trace #11447

Thihup opened this issue Dec 11, 2020 · 3 comments · Fixed by #11601

Comments

@Thihup
Copy link
Contributor

Thihup commented Dec 11, 2020

Currently, the default behavior using JPMS is that the stack trace doesn't show the version of the module. This is different from Hotspot, but I guess this is implementation-specific.

However, there is an option -verbose:stacktrace. Maybe we could show the module number using this option?

Example Stacktrace Hotspot:

javax.servlet.ServletException: Hi!
        at cloud.piranha.war.modular.Servlet.init(Servlet.java:39)
        at cloud.piranha.servlet.api@20.12.0-SNAPSHOT/javax.servlet.GenericServlet.init(GenericServlet.java:141)
        at cloud.piranha.webapp.impl@20.12.0-SNAPSHOT/cloud.piranha.webapp.impl.DefaultWebApplication.initializeServlet(DefaultWebApplication.java:1503)
        at cloud.piranha.webapp.impl@20.12.0-SNAPSHOT/cloud.piranha.webapp.impl.DefaultWebApplication.lambda$initializeServlets$15(DefaultWebApplication.java:1445)
        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.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at cloud.piranha.webapp.impl@20.12.0-SNAPSHOT/cloud.piranha.webapp.impl.DefaultWebApplication.initializeServlets(DefaultWebApplication.java:1444)
        at cloud.piranha.webapp.impl@20.12.0-SNAPSHOT/cloud.piranha.webapp.impl.DefaultWebApplication.initialize(DefaultWebApplication.java:1324)
        at cloud.piranha.server@20.12.0-SNAPSHOT/cloud.piranha.server.ServerPiranha.run(ServerPiranha.java:250)
        at cloud.piranha.server@20.12.0-SNAPSHOT/cloud.piranha.server.ServerPiranha.main(ServerPiranha.java:119)

Example Stacktrace OpenJ9:

javax.servlet.ServletException: Hi!
        at cloud.piranha.war.modular.Servlet.init(Servlet.java:39)
        at cloud.piranha.servlet.api/javax.servlet.GenericServlet.init(GenericServlet.java:141)
        at cloud.piranha.webapp.impl/cloud.piranha.webapp.impl.DefaultWebApplication.initializeServlet(DefaultWebApplication.java:1503)
        at cloud.piranha.webapp.impl/cloud.piranha.webapp.impl.DefaultWebApplication.lambda$initializeServlets$15(DefaultWebApplication.java:1445)
        at cloud.piranha.webapp.impl/cloud.piranha.webapp.impl.DefaultWebApplication$$Lambda$173/0x000000005865c160.accept(Unknown Source)
        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.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:497)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:487)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:239)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at cloud.piranha.webapp.impl/cloud.piranha.webapp.impl.DefaultWebApplication.initializeServlets(DefaultWebApplication.java:1444)
        at cloud.piranha.webapp.impl/cloud.piranha.webapp.impl.DefaultWebApplication.initialize(DefaultWebApplication.java:1324)
        at cloud.piranha.server/cloud.piranha.server.ServerPiranha.run(ServerPiranha.java:250)
        at cloud.piranha.server/cloud.piranha.server.ServerPiranha.main(ServerPiranha.java:119)
@Thihup
Copy link
Contributor Author

Thihup commented Dec 11, 2020

The StackTraceElement#toString today pass false fixed to the extended argument, maybe change to source != null

public String toString() {
	StringBuilder buf = new StringBuilder(80);
	Util.printStackTraceElement(this, source, buf, false);
	return buf.toString();
}
public String toString() {
	StringBuilder buf = new StringBuilder(80);
	Util.printStackTraceElement(this, source, buf, source != null);
	return buf.toString();
}

@pshipton
Copy link
Member

If OpenJ9 isn't printing module versions by default while Hotspot does, OpenJ9 should be fixed to match the behavior.

@pshipton pshipton added this to the Release 0.25 (Java 16) milestone Dec 11, 2020
@pshipton pshipton changed the title Show module version using -verbose:stacktrace Show module version in stack trace Jan 6, 2021
@sharon-wang
Copy link
Contributor

Reproduced the issue using the example program from #11452 (comment) enclosed in testModule with module version 1.0.

OpenJ9 Output

Exception in thread "main" java.lang.ClassNotFoundException: jakarta.servlet.http.Cookie
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:605)
	at java.base/java.lang.ClassLoader.loadClassHelper(ClassLoader.java:1183)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1098)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1081)
	at testModule/test.Main.main(Main.java:20)

RI Output

Exception in thread "main" java.lang.ClassNotFoundException: jakarta.servlet.http.Cookie
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:433)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:586)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at testModule@1.0/test.Main.main(Main.java:20)

I'll be updating StackTraceElement to show the module version by default to match the RI, and will check if the RI also shows module version for Throwable and match accordingly. Both OpenJ9 and the RI show module version in the stack trace for ThreadInfo already. I'll include the changes in #11601.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants