-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8371309: Diagnostic.getEndPosition can throw an NPE with typical broken code #28316
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
|
@lahodaj This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 148 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
It's my fault for provoking this issue with the commit you referenced - apologies, that change was overly optimistic. I agree the practical answer for now is to add back the null check. It makes me wonder if the specified behavior for
It seems like more realistic (and accurate) specification would be:
That's a separate question from this PR of course. |
vicente-romero-oracle
left a comment
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.
looks good
When starting the compiler via API, a
DiagnosticListenermay be provided, to which all reported errors and warnings are reported.The reported diagnostics are represented by
javax.tools.Diagnostic, which has (among others) methodgetEndPosition, which requires the end-pos-table to be set in theDiagnosticSourceobject for the given file (seeAbstractLog.sourceMap). But the end-pos-table is only set after the parse is done:jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java
Line 702 in 167c952
There are three problems with this:
Diagnosticis reported by the parser, and the clients code callsDiagnostic.getEndPosition, the end-pos-table is not set yet, and the method crashes with an NPEjdk/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java
Line 840 in 167c952
Diagnosticis reported for a tree by the parser, the tree on which theDiagnosticappear does not typically have the end position set yet - it is usually set only after the error/warning is reportedAll those problems used to be hidden by this check:
jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java
Line 649 in 6c48f4e
but that has been removed:
c793de9
I have tried to fix this properly, by deferring the errors from the parser to a later point, properly setting the end-pos-table, and handling implicitly parsed files more correctly:
https://github.com/openjdk/jdk/compare/master...lahodaj:jdk:JDK-8371309b?expand=1
but this change is a bit involved, and potentially a bit dangerous.
So, for now, I propose to reinstate the null check in
TreeInfo.getEndPos, to restore the JDK 25 behavior, and attempt to do the better solution later, hopefully earlier in the release cycle.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28316/head:pull/28316$ git checkout pull/28316Update a local copy of the PR:
$ git checkout pull/28316$ git pull https://git.openjdk.org/jdk.git pull/28316/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28316View PR using the GUI difftool:
$ git pr show -t 28316Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28316.diff
Using Webrev
Link to Webrev Comment