Skip to content

Commit 0bb4f09

Browse files
JavaStackTrace: Added support stack frame element class loaders and modules (#2658)
1 parent 0803525 commit 0bb4f09

File tree

3 files changed

+246
-11
lines changed

3 files changed

+246
-11
lines changed

Diff for: components/prism-javastacktrace.js

+50-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Specification:
2+
// https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Throwable.html#printStackTrace()
3+
14
Prism.languages.javastacktrace = {
25

36
// java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]
@@ -38,12 +41,30 @@ Prism.languages.javastacktrace = {
3841

3942
// at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
4043
// at org.hsqldb.jdbc.Util.throwError(Unknown Source) here could be some notes
44+
// at java.base/java.lang.Class.forName0(Native Method)
4145
// at Util.<init>(Unknown Source)
46+
// at com.foo.loader/[email protected]/com.foo.Main.run(Main.java:101)
47+
// at com.foo.loader//com.foo.bar.App.run(App.java:12)
48+
// at [email protected]/org.acme.Lib.test(Lib.java:80)
49+
// at MyClass.mash(MyClass.java:9)
50+
//
51+
// More information:
52+
// https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/StackTraceElement.html#toString()
53+
//
54+
// A valid Java module name is defined as:
55+
// "A module name consists of one or more Java identifiers (§3.8) separated by "." tokens."
56+
// https://docs.oracle.com/javase/specs/jls/se9/html/jls-6.html#jls-ModuleName
57+
//
58+
// A Java module version is defined by this class:
59+
// https://docs.oracle.com/javase/9/docs/api/java/lang/module/ModuleDescriptor.Version.html
60+
// This is the implementation of the `parse` method in JDK13:
61+
// https://github.com/matcdac/jdk/blob/2305df71d1b7710266ae0956d73927a225132c0f/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java#L1108
62+
// However, to keep this simple, a version will be matched by the pattern /@[\w$.+-]*/.
4263
'stack-frame': {
43-
pattern: /^[\t ]*at [\w$.]+(?:<init>)?\([^()]*\)/m,
64+
pattern: /^[\t ]*at (?:[\w$./]|@[\w$.+-]*\/)+(?:<init>)?\([^()]*\)/m,
4465
inside: {
4566
'keyword': {
46-
pattern: /^(\s*)at/,
67+
pattern: /^(\s*)at(?= )/,
4768
lookbehind: true
4869
},
4970
'source': [
@@ -74,8 +95,33 @@ Prism.languages.javastacktrace = {
7495
],
7596
'class-name': /[\w$]+(?=\.(?:<init>|[\w$]+)\()/,
7697
'function': /(?:<init>|[\w$]+)(?=\()/,
77-
'namespace': /[a-z]\w*/,
78-
'punctuation': /[.()]/
98+
'class-loader': {
99+
pattern: /(\s)[a-z]\w*(?:\.[a-z]\w*)*(?=\/[\w@$.]*\/)/,
100+
lookbehind: true,
101+
alias: 'namespace',
102+
inside: {
103+
'punctuation': /\./
104+
}
105+
},
106+
'module': {
107+
pattern: /([\s/])[a-z]\w*(?:\.[a-z]\w*)*(?:@[\w$.+-]*)?(?=\/)/,
108+
lookbehind: true,
109+
inside: {
110+
'version': {
111+
pattern: /(@)[\s\S]+/,
112+
lookbehind: true,
113+
alias: 'number'
114+
},
115+
'punctuation': /[@.]/
116+
}
117+
},
118+
'namespace': {
119+
pattern: /(?:[a-z]\w*\.)+/,
120+
inside: {
121+
'punctuation': /\./
122+
}
123+
},
124+
'punctuation': /[()/.]/
79125
}
80126
},
81127

Diff for: components/prism-javastacktrace.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/languages/javastacktrace/stack-frame_feature.test

+195-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ at Main.main(Main.java:13)
22
at Main.main(Main.java:13) Same but with some additional notes
33
at com.foo.bar.Main$FooBar.main(Native Method)
44
at Main$FooBar.<init>(Unknown Source)
5+
at java.base/java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:69)
6+
at java.base/java.lang.Class.forName0(Native Method)
7+
at com.foo.loader/[email protected]/com.foo.Main.run(Main.java:101)
8+
at com.foo.loader//com.foo.bar.App.run(App.java:12)
9+
at [email protected]/org.acme.Lib.test(Lib.java:80)
10+
at MyClass.mash(MyClass.java:9)
11+
12+
// not to forget our swiss friends
13+
at at.foo.bar.Main$FooBar.main(Native Method)
514

615
----------------------------------------------------
716

@@ -37,12 +46,14 @@ at Main$FooBar.<init>(Unknown Source)
3746

3847
["stack-frame", [
3948
["keyword", "at"],
40-
["namespace", "com"],
41-
["punctuation", "."],
42-
["namespace", "foo"],
43-
["punctuation", "."],
44-
["namespace", "bar"],
45-
["punctuation", "."],
49+
["namespace", [
50+
"com",
51+
["punctuation", "."],
52+
"foo",
53+
["punctuation", "."],
54+
"bar",
55+
["punctuation", "."]
56+
]],
4657
["class-name", "Main$FooBar"],
4758
["punctuation", "."],
4859
["function", "main"],
@@ -63,6 +74,184 @@ at Main$FooBar.<init>(Unknown Source)
6374
["keyword", "Unknown Source"]
6475
]],
6576
["punctuation", ")"]
77+
]],
78+
79+
["stack-frame", [
80+
["keyword", "at"],
81+
["module", [
82+
"java",
83+
["punctuation", "."],
84+
"base"
85+
]],
86+
["punctuation", "/"],
87+
["namespace", [
88+
"java",
89+
["punctuation", "."],
90+
"util",
91+
["punctuation", "."],
92+
"jar",
93+
["punctuation", "."]
94+
]],
95+
["class-name", "JavaUtilJarAccessImpl"],
96+
["punctuation", "."],
97+
["function", "ensureInitialization"],
98+
["punctuation", "("],
99+
["source", [
100+
["file", "JavaUtilJarAccessImpl.java"],
101+
["punctuation", ":"],
102+
["line-number", "69"]
103+
]],
104+
["punctuation", ")"]
105+
]],
106+
107+
["stack-frame", [
108+
["keyword", "at"],
109+
["module", [
110+
"java",
111+
["punctuation", "."],
112+
"base"
113+
]],
114+
["punctuation", "/"],
115+
["namespace", [
116+
"java",
117+
["punctuation", "."],
118+
"lang",
119+
["punctuation", "."]
120+
]],
121+
["class-name", "Class"],
122+
["punctuation", "."],
123+
["function", "forName0"],
124+
["punctuation", "("],
125+
["source", [
126+
["keyword", "Native Method"]
127+
]],
128+
["punctuation", ")"]
129+
]],
130+
131+
["stack-frame", [
132+
["keyword", "at"],
133+
["class-loader", [
134+
"com",
135+
["punctuation", "."],
136+
"foo",
137+
["punctuation", "."],
138+
"loader"
139+
]],
140+
["punctuation", "/"],
141+
["module", [
142+
"foo",
143+
["punctuation", "@"],
144+
["version", "9.0"]
145+
]],
146+
["punctuation", "/"],
147+
["namespace", [
148+
"com",
149+
["punctuation", "."],
150+
"foo",
151+
["punctuation", "."]
152+
]],
153+
["class-name", "Main"],
154+
["punctuation", "."],
155+
["function", "run"],
156+
["punctuation", "("],
157+
["source", [
158+
["file", "Main.java"],
159+
["punctuation", ":"],
160+
["line-number", "101"]
161+
]],
162+
["punctuation", ")"]
163+
]],
164+
165+
["stack-frame", [
166+
["keyword", "at"],
167+
["class-loader", [
168+
"com",
169+
["punctuation", "."],
170+
"foo",
171+
["punctuation", "."],
172+
"loader"
173+
]],
174+
["punctuation", "/"],
175+
["punctuation", "/"],
176+
["namespace", [
177+
"com",
178+
["punctuation", "."],
179+
"foo",
180+
["punctuation", "."],
181+
"bar",
182+
["punctuation", "."]
183+
]],
184+
["class-name", "App"],
185+
["punctuation", "."],
186+
["function", "run"],
187+
["punctuation", "("],
188+
["source", [
189+
["file", "App.java"],
190+
["punctuation", ":"],
191+
["line-number", "12"]
192+
]],
193+
["punctuation", ")"]
194+
]],
195+
196+
["stack-frame", [
197+
["keyword", "at"],
198+
["module", [
199+
"acme",
200+
["punctuation", "@"],
201+
["version", "2.1"]
202+
]],
203+
["punctuation", "/"],
204+
["namespace", [
205+
"org",
206+
["punctuation", "."],
207+
"acme",
208+
["punctuation", "."]
209+
]],
210+
["class-name", "Lib"],
211+
["punctuation", "."],
212+
["function", "test"],
213+
["punctuation", "("],
214+
["source", [
215+
["file", "Lib.java"],
216+
["punctuation", ":"],
217+
["line-number", "80"]
218+
]],
219+
["punctuation", ")"]
220+
]],
221+
222+
["stack-frame", [
223+
["keyword", "at"],
224+
["class-name", "MyClass"],
225+
["punctuation", "."],
226+
["function", "mash"],
227+
["punctuation", "("],
228+
["source", [
229+
["file", "MyClass.java"],
230+
["punctuation", ":"],
231+
["line-number", "9"]
232+
]],
233+
["punctuation", ")"]
234+
]],
235+
236+
"\n\n// not to forget our swiss friends\n",
237+
["stack-frame", [
238+
["keyword", "at"],
239+
["namespace", [
240+
"at",
241+
["punctuation", "."],
242+
"foo",
243+
["punctuation", "."],
244+
"bar",
245+
["punctuation", "."]
246+
]],
247+
["class-name", "Main$FooBar"],
248+
["punctuation", "."],
249+
["function", "main"],
250+
["punctuation", "("],
251+
["source", [
252+
["keyword", "Native Method"]
253+
]],
254+
["punctuation", ")"]
66255
]]
67256
]
68257

0 commit comments

Comments
 (0)