Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
/ jdk20 Public archive

8298727: Trees.getPath may crash for unnamed package #31

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Dec 14, 2022

Considering an empty package-info.java file is normally accepted by javac (as a package-info for the unnamed module). But, if Trees.getPath is used on the unnamed package, a NPE occurs:

java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.tree.JCTree.accept(com.sun.tools.javac.tree.JCTree$Visitor)" because "tree" is null
at jdk.compiler/com.sun.tools.javac.tree.TreeInfo.declarationFor(TreeInfo.java:811)
at jdk.compiler/com.sun.tools.javac.model.JavacElements.getTreeAndTopLevel(JavacElements.java:779)
at jdk.compiler/com.sun.tools.javac.model.JavacElements.getTreeAndTopLevel(JavacElements.java:799)
at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getPath(JavacTrees.java:331)
at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getPath(JavacTrees.java:321)

The reason is that Env.tree is initialized to the package clause in Enter.visitTopLevel, but when the package clause is missing, Env.tree is null, leading to the error above.

The proposed fix is to set Env.tree to the top-level tree in this case, to keep it non-null. As the empty package-info can be compiled, it seems reasonable for the model to work on is as well, so a non-null tree needs to be set, and there's no other tree that could be used, I believe.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8298727: Trees.getPath may crash for unnamed package

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk20 pull/31/head:pull/31
$ git checkout pull/31

Update a local copy of the PR:
$ git checkout pull/31
$ git pull https://git.openjdk.org/jdk20 pull/31/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31

View PR using the GUI difftool:
$ git pr show -t 31

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk20/pull/31.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 14, 2022

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 14, 2022
@openjdk
Copy link

openjdk bot commented Dec 14, 2022

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Dec 14, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 14, 2022

Webrevs

Copy link

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks sensible

@openjdk
Copy link

openjdk bot commented Dec 14, 2022

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

8298727: Trees.getPath may crash for unnamed package

Reviewed-by: vromero

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 6 new commits pushed to the master branch:

  • 581f9f2: 8297235: ZGC: assert(regs[i] != regs[j]) failed: Multiple uses of register: rax
  • 0eeaf6b: 8298649: JFR: RemoteRecordingStream support for checkpoint event sizes beyond u4
  • 2791701: 8298296: gc/TestFullGCCount.java fails with "System.gc collections miscounted."
  • 0bbc418: 8294902: Undefined Behavior in C2 regalloc with null references
  • 9bcdfc4: 8298425: System.console().readLine() hangs in jshell
  • 27d4971: 8298520: C2: assert(found_opaque == res) failed: wrong pattern

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 14, 2022
@lahodaj
Copy link
Contributor Author

lahodaj commented Dec 15, 2022

Thanks for the review, Vicente!

@lahodaj
Copy link
Contributor Author

lahodaj commented Dec 15, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 15, 2022

Going to push as commit 22a6b59.
Since your change was applied there have been 9 commits pushed to the master branch:

  • 323e574: 8298371: monitors_on_stack extracts unprocessed oops
  • 80cadd4: 8298785: gc/TestFullGCCount.java fails with "invalid boolean value: null' for expression vm.opt.ExplicitGCInvokesConcurrent'"
  • ebc4710: 8298277: Replace "session" with "scope" for FFM access
  • 581f9f2: 8297235: ZGC: assert(regs[i] != regs[j]) failed: Multiple uses of register: rax
  • 0eeaf6b: 8298649: JFR: RemoteRecordingStream support for checkpoint event sizes beyond u4
  • 2791701: 8298296: gc/TestFullGCCount.java fails with "System.gc collections miscounted."
  • 0bbc418: 8294902: Undefined Behavior in C2 regalloc with null references
  • 9bcdfc4: 8298425: System.console().readLine() hangs in jshell
  • 27d4971: 8298520: C2: assert(found_opaque == res) failed: wrong pattern

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 15, 2022
@openjdk openjdk bot closed this Dec 15, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 15, 2022
@openjdk
Copy link

openjdk bot commented Dec 15, 2022

@lahodaj Pushed as commit 22a6b59.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants