Skip to content

fixes evaluation order of stack trace #8568

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.util.ElementFilter;
import javax.swing.Action;
import jdk.internal.net.http.common.Log;
import org.netbeans.api.extexecution.print.LineConvertors.FileLocator;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.JavaSource;
Expand All @@ -38,6 +39,8 @@
import org.netbeans.modules.gsf.testrunner.api.CommonUtils;
import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodNode;
import org.netbeans.modules.gsf.testrunner.ui.api.TestsuiteNode;
import org.netbeans.modules.java.testrunner.JavaRegexpPatterns;
import org.netbeans.modules.java.testrunner.JavaRegexpUtils;
import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
import org.netbeans.modules.junit.api.JUnitTestSuite;
Expand Down Expand Up @@ -157,29 +160,42 @@ public void openCallstackFrame(Node node, String frameInfo) {
}
// Method node might belong to an inner class
FileObject testfo = methodNode.getTestcase().getClassFileObject(true);
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.
int index = 0;//st.length - 1;
//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 < st.length) {
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 == st.length) {
index=0;
while(true) {
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);
break;
}
}
}
// if that fails, return the test file object.
if (file == null) {

file = testfo;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,18 @@ public void openCallstackFrame(Node node, @NonNull String frameInfo) {
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
//if it's a failure text, grab the testcase's own line from the stack.
String fqMethodName= methodNode.getTestcase().getClassName()+ '.'+ methodNode.getTestcase().getName();
String[] st = methodNode.getTestcase().getTrouble().getStackTrace();
if ((st != null) && (st.length > 0)) {
int index = st.length - 1;
int index = 0;//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) {
file = UIJavaUtils.getFile(st[index], lineNumStorage, locator);
index = index - 1;
while (!testfo.equals(file) && index < st.length) {
if (st[index].contains(fqMethodName)) {
file = UIJavaUtils.getFile(st[index], lineNumStorage, locator);
break;
}
index++;
}
}
}
Expand Down