matthiasblaesing commented on code in PR #8568:
URL: https://github.com/apache/netbeans/pull/8568#discussion_r3006189983
##########
java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java:
##########
@@ -186,18 +188,18 @@ public void openCallstackFrame(Node node, @NonNull String
frameInfo) {
FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage,
locator);
//lineNumStorage -1 means no regexp for stacktrace was matched.
if (testfo != null && file == null &&
methodNode.getTestcase().getTrouble() != null && lineNumStorage[0] == -1) {
- //213935 we could not recognize the stack trace line and map
it to known file
+ //213935 we could not recognize the stack trace line and map it to
known file
//if it's a failure text, grab the testcase's own line from the
stack.
String[] st =
methodNode.getTestcase().getTrouble().getStackTrace();
- if ((st != null) && (st.length > 0)) {
- int index = st.length - 1;
- //213935 we need to find the testcase linenumber to jump
to.
- // and ignore the infrastructure stack lines in the process
- while (!testfo.equals(file) && index != -1) {
+ for (int index = 0; !testfo.equals(file) && index < st.length;
index++) {
+ String trimmed = JavaRegexpUtils.specialTrim(st[index]);
+ if
(trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX_CATCH)
+ ||
trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX)) {
file = UIJavaUtils.getFile(st[index], lineNumStorage,
locator);
- index -= 1;
+ break;
}
}
+
}
Review Comment:
I assume that we talk about the same top and bottom definitions. I define
the top frame as the frame that contains the method that "executes as
thread"/is the root of the stack trace. This method invokes other methods, and
the stack goes down from there. The bottom of the stack trace is thus the last
method that was invoked.
Now please have a look at the screenshot of my last comment. What you see
there is the `st` array, the stack trace. If you look closely, you notice, that
the order of the lines is so, that the highest index holds the top most frame.
`st[9]` reads `at java.base/java.lang.Thread.run(Thrad.java:1583)`. So if
iteration starts at the last index, the stack trace is traversed from top to
bottom.
This is exactly what is done (this is current master):
https://github.com/apache/netbeans/blob/26a05a6e2386372145e4894e70347d2f69ef8b98/java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java#L171-L184
1. line 172 initializes index to the last position
2. iteration starts
3. `UIJavaUtils` is used to find the file and line the stack trace line
points to (line 176)
4. the next index to check is the previous entry in the stack trace array
(line 177) (we are going down the stack)
5. ignoring the IMHO bogus lines 180-182, iteration ends when
a. the file determined for the stack trace line matches the file for the
test case or
b. the bottom of the stack trace is reached or
c. the check in lines 180-182 is true
5c tests if the `file` is in the same order as `testfo` (the testcase file)
or in a folder below that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists