homberghp commented on code in PR #8568:
URL: https://github.com/apache/netbeans/pull/8568#discussion_r3008077305


##########
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:
   @matthiasblaesing 
   I use the top and bottom definitions as implied by 
[Throwable#getStackTrace](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Throwable.html#getStackTrace()).
   
   That makes the top the element at index 0. That makes the top the last 
method call, and the bottom the actual start of the program, in this case, the 
start of the Junit runner.
   
   @neilcsmith-net, Thanks for the links to the earlier work, though I can't 
access the bugzilla site. 
   
   For the ANT solution:
   In my approach, I first iterate through the stack trace to find the fully 
qualified method name.
   If that succeeds, I have the best possible match.
   If not, I simply return the top-most stack trace, and  try to assign the 
file with getFile.... 
   
   I think that the actual order of evaluation matters.
   It might very well be the line that triggers the break, which tests for a 
match with the fully qualified file name. 
   ```java
       if (st[index].contains(fqMethodName)) {
                file = UIJavaUtils.getFile(st[index], lineNumStorage, locator);
                break;
       }
   ```
   But that was already in the original solution.
   
   I have seen the effect of considering a sibling; that actually triggered me 
to raise issue #8567. I have updated the issue description accordingly. I have 
not yet written an actual (Junit) test, because that would either lead to a 
very complex test setup or some major refactoring in the XXNodeOpener files, to 
extract the iteration and its result into separate (testable) methods.
   What I observed (and still can observe) in my experiments is that the top of 
the stack is used with 'goto source', whereas the actual stack line I want to 
use is a few lines down in the stack trace, so with a higher index.
   



-- 
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

Reply via email to