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


##########
java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java:
##########
@@ -150,37 +150,53 @@ public void openCallstackFrame(Node node, String 
frameInfo) {
             }
         }
         // #213935 - copied from 
org.netbeans.modules.maven.junit.nodes.AntJUnitNodeOpener
-        JUnitTestMethodNode methodNode = 
(JUnitTestMethodNode)UIJavaUtils.getTestMethodNode(node);
+        JUnitTestMethodNode methodNode = (JUnitTestMethodNode) 
UIJavaUtils.getTestMethodNode(node);
         FileLocator locator = 
methodNode.getTestcase().getSession().getFileLocator();
         if (locator == null) {
             return;
         }
         // Method node might belong to an inner class
         FileObject testfo = methodNode.getTestcase().getClassFileObject(true);
-       if(testfo == null) {
-           return;
-       }
+        String fqMethodName = methodNode.getTestcase().getClassName() + '.' + 
methodNode.getTestcase().getName();
+        if (testfo == null) {
+            return;
+        }
         final int[] lineNumStorage = new int[1];
         FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage, 
locator);
         //lineNumStorage -1 means no regexp for stacktrace was matched.
         if ((file == null) && (methodNode.getTestcase().getTrouble() != null) 
&& lineNumStorage[0] == -1) {
-            //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.
-            boolean methodNodeParentOfStackTraceNode = false;
             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.
+                //Jump to the first line matching the fully qualified test 
method name.
                 // and ignore the infrastructure stack lines in the process
-                while (!testfo.equals(file) && index != -1 && 
!methodNodeParentOfStackTraceNode) {
-                    file = UIJavaUtils.getFile(st[index], lineNumStorage, 
locator);
-                    index = index - 1;
-                    // if frameInfo.isEmpty() == true, user clicked on a 
failed method node. 
-                    // Try to find if the stack trace node is relevant to the 
method node
-                    if(file != null && frameInfo.isEmpty()) {
-                        methodNodeParentOfStackTraceNode = 
FileUtil.isParentOf(testfo.getParent(), file);
+                while (index >= 0) {
+                    if (st[index].contains(fqMethodName)) {
+                        file = UIJavaUtils.getFile(st[index], lineNumStorage, 
locator);
+                        break;
+                    }
+                    index--;
+                }
+                // if not found, return top line of stack trace.
+                if (index == -1) {

Review Comment:
   The comment above the second loop now contradicts what actually happens. The 
reversed list makes the stacktrace go upside down, so the first match that 
looks like a stack trace is chosen.
   
   I my self keep thinking that the stack traversal from top to bottom (i.e. 
start at index 0) is the preferred approach. However, that does not happen here.
   If the second loop should do what the comment says, then that should surely 
start at index 0. 
   The current code is quite hard to test, unit test wise, because its effect 
is only observable by side effects in the UI.



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