-
Notifications
You must be signed in to change notification settings - Fork 348
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
Issue#1395 : Dump on error fix #3406
Changes from 35 commits
97ff12d
629a1a9
deab153
c0e6deb
d1ffe78
11e70d3
25b602a
4719fac
1e1ce11
eb424fd
c324094
941cab0
d71f608
2237a00
53a6c12
4bfe445
46aef3a
e5efd64
7b431cb
8f4123a
c16f886
987c560
f7cb763
8de96f8
80ac56b
d11fcf7
c0d2ff5
340c22d
c82f4b5
42aeb4f
e1c8ac2
f712249
b615462
7d44943
3f99303
062a284
4ccbadb
4460e8c
7f7ce23
b434c02
8fafccd
004d5e8
ae972ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -568,10 +568,11 @@ protected void warnUnneededSuppressions() { | |
protected void printOrStoreMessage( | ||
Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root) { | ||
assert this.currentRoot == root; | ||
StackTraceElement[] trace = Thread.currentThread().getStackTrace(); | ||
if (messageStore == null) { | ||
super.printOrStoreMessage(kind, message, source, root); | ||
super.printOrStoreMessage(kind, message, source, root, trace); | ||
} else { | ||
CheckerMessage checkerMessage = new CheckerMessage(kind, message, source, this); | ||
CheckerMessage checkerMessage = new CheckerMessage(kind, message, source, this, trace); | ||
messageStore.add(checkerMessage); | ||
} | ||
} | ||
|
@@ -586,7 +587,7 @@ protected void printOrStoreMessage( | |
private void printStoredMessages(CompilationUnitTree unit) { | ||
if (messageStore != null) { | ||
for (CheckerMessage msg : messageStore) { | ||
super.printOrStoreMessage(msg.kind, msg.message, msg.source, unit); | ||
super.printOrStoreMessage(msg.kind, msg.message, msg.source, unit, msg.trace); | ||
} | ||
} | ||
} | ||
|
@@ -599,6 +600,8 @@ private static class CheckerMessage { | |
final String message; | ||
/** The source code that the message is about. */ | ||
final @InternedDistinct Tree source; | ||
/** Stores the stack trace till the point the checker encounters an error. */ | ||
final StackTraceElement @Nullable [] trace; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the field There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the IDE added it automatically when I initialized it. I have removed the annotation since it was, as you said, redundant. |
||
|
||
/** | ||
* The checker that issued this message. The compound checker that depends on this checker | ||
|
@@ -609,20 +612,23 @@ private static class CheckerMessage { | |
/** | ||
* Create a new CheckerMessage. | ||
* | ||
* @param kind the severity of the message | ||
* @param message the text of the message | ||
* @param source the source code that the message is about | ||
* @param checker the checker that issued the message. | ||
* @param kind kind of diagnostic, for example, error or warning | ||
* @param message error message that needs to be printed | ||
* @param source tree element causing the error | ||
* @param checker the type-checker in use | ||
* @param trace the stack trace when the checker encounters an error | ||
*/ | ||
private CheckerMessage( | ||
Diagnostic.Kind kind, | ||
String message, | ||
@FindDistinct Tree source, | ||
@FindDistinct BaseTypeChecker checker) { | ||
@FindDistinct BaseTypeChecker checker, | ||
StackTraceElement @Nullable [] trace) { | ||
this.kind = kind; | ||
this.message = message; | ||
this.source = source; | ||
this.checker = checker; | ||
this.trace = trace; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -52,6 +52,7 @@ | |||
import javax.lang.model.element.TypeElement; | ||||
import javax.lang.model.util.Elements; | ||||
import javax.lang.model.util.Types; | ||||
import javax.tools.Diagnostic; | ||||
import javax.tools.Diagnostic.Kind; | ||||
import org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey; | ||||
import org.checkerframework.checker.interning.qual.InternedDistinct; | ||||
|
@@ -317,6 +318,10 @@ | |||
// org.checkerframework.framework.util.typeinference.DefaultTypeArgumentInference | ||||
"showInferenceSteps", | ||||
|
||||
// Output a stack trace when reporting errors or warnings | ||||
// org.checkerframework.common.basetype.SourceChecker.printStackTrace() | ||||
"dumpOnErrors", | ||||
wmdietl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
/// Visualizing the CFG | ||||
|
||||
// Implemented in the wrapper rather than this file, but worth noting here. | ||||
|
@@ -1084,6 +1089,43 @@ protected void printOrStoreMessage( | |||
Trees.instance(processingEnv).printMessage(kind, message, source, root); | ||||
} | ||||
|
||||
/** | ||||
* printOrStoreMessage method with an added stack trace argument. The stack trace is printed | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like for other overloaded methods, start out with the normal description of what the method is for and then describe the differences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the documentation in my latest commit. |
||||
* when the dumpOnErrors option is enabled. | ||||
* | ||||
* @param kind the kind of message to print | ||||
* @param message the message text | ||||
* @param source the souce code position of the diagnostic message | ||||
* @param root the compilation unit | ||||
* @param trace the stack trace where the checker encountered an error | ||||
*/ | ||||
protected void printOrStoreMessage( | ||||
wmdietl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
javax.tools.Diagnostic.Kind kind, | ||||
String message, | ||||
Tree source, | ||||
CompilationUnitTree root, | ||||
StackTraceElement[] trace) { | ||||
Trees.instance(processingEnv).printMessage(kind, message, source, root); | ||||
wmdietl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
printStackTrace(trace); | ||||
} | ||||
|
||||
/** | ||||
* Output the given stack trace if the "dumpOnErrors" option is enabled. | ||||
* | ||||
* @param trace stack trace when the checker encountered a warning/error | ||||
*/ | ||||
private void printStackTrace(StackTraceElement[] trace) { | ||||
boolean dumpOnErrors = | ||||
getOptions().containsKey("dumpOnErrors") && getBooleanOption("dumpOnErrors", true); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally tried There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a bit odd, looking at checker-framework/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java Line 1589 in 3498970
Can you investigate why this doesn't work as specified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is simply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
if (dumpOnErrors) { | ||||
StringBuilder msg = new StringBuilder(); | ||||
for (StackTraceElement elem : trace) { | ||||
msg.append("\tat " + elem + "\n"); | ||||
} | ||||
message(Diagnostic.Kind.NOTE, msg.toString()); | ||||
} | ||||
} | ||||
|
||||
/////////////////////////////////////////////////////////////////////////// | ||||
/// Diagnostic message formatting | ||||
/// | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the stack trace when it encountered an error, so this should be something like
The stack trace when the message is created.
Also change the parameter documentation to the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the field and parameter description in my latest commit.