-
Notifications
You must be signed in to change notification settings - Fork 0
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
1395 dump on error fix #2
Conversation
This reverts commit fd536c4.
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.
Thanks for fixing this issue!
@@ -565,10 +565,13 @@ protected void warnUnneededSuppressions() { | |||
protected void printOrStoreMessage( | |||
Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root) { | |||
assert this.currentRoot == root; | |||
StackTraceElement[] trace = new RuntimeException().getStackTrace(); |
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.
Use Thread.getStackTrace()
https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getStackTrace() instead of creating that exception object.
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 used Thread.currentThread().getStackTrace() to acquire the stack trace.
if (messageStore == null) { | ||
super.printOrStoreMessage(kind, message, source, root); | ||
this.printStackTrace(trace); |
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.
You don't need the explicit this
in these calls.
*/ | ||
private void printStackTrace(StackTraceElement[] trace) { | ||
boolean dumpOnErrors = | ||
(processingEnv != null |
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.
Instead of all this you can simply call getBooleanOption
? https://github.com/typetools/checker-framework/blob/master/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java#L1591
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 used getBooleanOption instead of the previous logic, however, in this one, I have to provide a boolean value to the command line option for the flag to function.
Ex : javac -AdumpOnErrors=true -processor org.checkerframework.checker.nullness.NullnessChecker -implicit:class Test.java
&& processingEnv.getOptions() != null | ||
&& processingEnv.getOptions().containsKey("dumpOnErrors")); | ||
if (dumpOnErrors) { | ||
System.err.println(new RuntimeException().toString()); |
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.
You don't want this output, as it's a stacktrace in this same location for every error.
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 removed this statement in my latest commit
if (dumpOnErrors) { | ||
System.err.println(new RuntimeException().toString()); | ||
for (StackTraceElement elem : trace) { | ||
System.err.println("\tat " + elem); |
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.
Don't use System.err
for any compiler output, always use the proper messager.
I would suggest using https://github.com/typetools/checker-framework/blob/master/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java#L1058 with diagnostic kind NOTE
.
As you also have the diagnostic source, you could also use that location for the warning. How does doe
output the message?
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 used the given function to print the stack trace. I observed the -doe outputs using a printWriter in the Log.java file.
@@ -600,6 +623,17 @@ private void printStoredMessages(CompilationUnitTree unit) { | |||
*/ | |||
final BaseTypeChecker checker; | |||
|
|||
/** Stores the stack trace till the point the checker encounters an error. */ | |||
StackTraceElement[] trace; |
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.
Make final.
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.
The field can be null, right? So it should be StackTraceElement @Nullable [] trace
.
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 made the changes in my latest commit
* @param message error message that needs to be printed | ||
* @param source tree element causing the error | ||
* @param checker the type-checker in use | ||
*/ | ||
private CheckerMessage( | ||
Diagnostic.Kind kind, String message, Tree source, BaseTypeChecker checker) { | ||
this.kind = kind; |
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 constructor should call the other constructor, providing null
for the trace.
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 made the changes in my latest commit
String message, | ||
Tree source, | ||
BaseTypeChecker checker, | ||
StackTraceElement[] trace) { |
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.
Also nullable.
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 made the changes in my latest commit
@@ -323,6 +323,10 @@ | |||
// org.checkerframework.framework.util.typeinference.DefaultTypeArgumentInference | |||
"showInferenceSteps", | |||
|
|||
// Output stack trace when checker encounters errors | |||
// org.checkerframework.common.basetype.BaseTypeChecker.printStackTrace() | |||
"dumpOnErrors", |
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.
You should also add documentation to the manual.
There is already a comment on doe
https://github.com/typetools/checker-framework/blob/d11aeaedaf4c039beb648ee0e3c177f894c060df/docs/manual/introduction.tex#L835
There you should mention this option.
You also need to document the feature itself, here in the introduction (find the appropriate place there) and in the corresponding section.
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 added the documentation in the introduction.tex file in the debugging section.
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 still assigned to you, so I wasn't sure whether it's ready for another review. Find a few comments. Please move to typetools to not drop the ball on this.
docs/manual/introduction.tex
Outdated
@@ -792,6 +792,10 @@ | |||
Print information about the git repository from which the Checker Framework | |||
was compiled. | |||
|
|||
\item | |||
\<-AdumpOnErrors> |
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.
Merge this with the amount of detail
section earlier in this document and then add the details in \ref{creating-debugging-options-detail}
.
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 added the documentation in their corresponding sections in my latest commit
docs/manual/introduction.tex
Outdated
@@ -792,6 +792,10 @@ | |||
Print information about the git repository from which the Checker Framework | |||
was compiled. | |||
|
|||
\item | |||
\<-AdumpOnErrors> | |||
Prints the stack trace when the checker framework encounters an error. |
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.
checker framework
should be Checker Framework
to be consistent.
Also output a stack trace when errors or warnings are reported.
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 made the changes in my latest commit
} | ||
|
||
/** | ||
* Prints given stack trace of runtime exception if -AdumpOnErrors flag is passed as compilation |
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.
Output the given stack trace if the "dumpOnErrors" option is enabled.
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 made the changes in my latest commit
@@ -323,6 +323,10 @@ | |||
// org.checkerframework.framework.util.typeinference.DefaultTypeArgumentInference | |||
"showInferenceSteps", | |||
|
|||
// Output stack trace when checker encounters errors | |||
// org.checkerframework.common.basetype.BaseTypeChecker.printStackTrace() |
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.
Shouldn't the option be handled in this class, in method printOrStoreMessage
, too?
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 thought we had to mention the place where the dumpOnErrors option was being checked. Since I was checking for the option in the printStackTrace() method, I wrote its path. The option is not used at all in the printOrStoreMessage (only the printStackTrace() method is called). Currently, I have not made any changes. Please let me know what you think I should do.
…4/checker-framework into 1395-dump-on-error-fix
Now that there is typetools#3406 don't you want to close this PR? |
Fix for issue typetools#1395 (dump-on-error). Compound checkers such as nullness and index checkers were not giving adequate stack trace to pin-point where the error in the code had occurred. This was because in BaseTypeChecker, errors due to checkers with subcheckers were stored in CheckerMessage but those without were printed right away giving a correct stack trace. This storage caused the stack trace to unwind and take a different path. Since, all errors were stored in the same place, they gave the same stack trace when the -doe option is used. To fix this problem, I added a CheckerMessage constructor to store the stack trace when the error occurred. Then, I added a method to print this stored stack trace for all the stored errors. The code gives the correct stack trace when used with the '-AdumpOnErrors' compiler option.