jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8335385: javac crash on unattributed piece of AST

Open lahodaj opened this issue 1 year ago • 4 comments

Consider the following sources:

//B.java
package p;

public class B {
    public interface I {}
}
Test.java
import p.B.I;

Then compile B, remove the I nested interface, and try to compile Test with the remaining classfiles of B on the classpath:

$ javac -d out B.java
$ rm out/p/B\$I.class
$ javac -classpath out -XDdev Test.java
Test.java:1: error: cannot access I
import p.B.I;
          ^
  class file for p.B$I not found
1 error
An exception has occurred in the compiler (24-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com/) after checking the Bug Database (https://bugs.java.com/) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot read field "owner" because "s.sym" is null
        at jdk.compiler/com.sun.tools.javac.comp.Check.isCanonical(Check.java:4264)
        at jdk.compiler/com.sun.tools.javac.comp.Check.checkCanonical(Check.java:4256)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.doImport(TypeEnter.java:466)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.handleImports(TypeEnter.java:416)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.resolveImports(TypeEnter.java:389)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.lambda$ensureImportsChecked$0(TypeEnter.java:165)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.finishImports(TypeEnter.java:217)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.ensureImportsChecked(TypeEnter.java:165)
        at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:650)
        at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:600)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1077)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:948)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
printing javac parameters to: /tmp/javac.20240701_092709.args

The reason is that when the import is attributed, Resolve.findIdentInType is called to find I in p.B. It will, however, fail with a CompletionFailure, as I does not exist. And the CompletionFailure won't be called sooner than in Attr.attribTree, and as a consequence, the sym field of the p.B.I select will remain null, as the code that sets it will be skipped due to the CompletionFailure. This then leads to the follow-up NPE.

The proposal herein is to change Resolve.findIdentInType and Resolve.findIdent to handle CompletionFailures immediately, report an error, and return a "missing" Symbol. Note that Resolve.findIdentInPackage will not throw CompletionFailures, as it uses Resolve.loadClass, which handles CompletionFailures. So, this should be making the behavior consistent across findIdent, findIdentInPackage and findIdentInType.


Progress

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

Warning

 ⚠️ Found leading lowercase letter in issue title for 8335385: javac crash on unattributed piece of AST

Issue

  • JDK-8335385: javac crash on unattributed piece of AST (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19969

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19969.diff

Webrev

Link to Webrev Comment

lahodaj avatar Jul 01 '24 12:07 lahodaj

:wave: 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.

bridgekeeper[bot] avatar Jul 01 '24 12:07 bridgekeeper[bot]

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

8335385: javac crash on unattributed piece of AST

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

  • 6923a5114b2a9f02f0d6f0fefc21141ac3b9322a: 8335607: Serial: Remove unused collection_attempt_is_safe
  • 5866b16dbca3f63770c8792d204dabdf49b59839: 8335411: RISC-V: Optimize encode_heap_oop when oop is not null
  • 6db4c6a772df856fc3099c32a5b2c102a30d360c: 8335536: Fix assertion failure in IdealGraphPrinter when append is true
  • 350f9c1947b0eab3ee233516ceefca1e25de9583: 8322812: Manpage for jcmd is missing JFR.view command
  • c06b75ff88babf57bdcd0919ea177ff363fd858b: 8335591: Fix -Wzero-as-null-pointer-constant warnings in ConcurrentHashTable
  • 6c84e9c8cb71aac103901c0d92fe6ae51aabff15: 8335544: Serial: Remove unused _should_allocate_from_space
  • 4d2f73764bcd5ff62fbdb9d406d4180ae09613ff: 8335357: Delete HotSpotJDKReflection.oopSizeOffset
  • 77a7078b82fd0cb3cfa13685072f04fdef33758b: 8335593: Fix -Wzero-as-null-pointer-constant warning in Type_Array ctor
  • f3f90dc11a5cbc146a5ef8a73eadf4168373838d: 8335592: Fix -Wzero-as-null-pointer-constant warnings in RootNode ctor
  • 7bc8f9c150cbf457edf6144adba734ecd5ca5a0f: 8335589: Fix -Wzero-as-null-pointer-constant warnings in IdealLoopTree ctor
  • ... and 26 more: https://git.openjdk.org/jdk/compare/53242cdf9ef17c502ebd541e84370e7c158639c1...master

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[bot] avatar Jul 01 '24 12:07 openjdk[bot]

@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[bot] avatar Jul 01 '24 12:07 openjdk[bot]

Webrevs

mlbridge[bot] avatar Jul 01 '24 12:07 mlbridge[bot]

/integrate

lahodaj avatar Jul 04 '24 08:07 lahodaj

Going to push as commit 3e3f83f62c67caf960ca031439b022f915e1102a. Since your change was applied there have been 49 commits pushed to the master branch:

  • b20e8c8e85e0a0e96ae648f42ff803f1c83f6291: 8335397: Improve reliability of TestRecursiveMonitorChurn.java
  • 38a578d547f39c3637d97f5e0242f4a69f3bbb31: 8334738: os::print_hex_dump should optionally print ASCII
  • 7b894bc4afa96bc04f0d58042f69becadb573e20: 8332786: When dumping static CDS archives, explicitly assert that we don't use a CDS archive
  • e01626cf09850f7b0af33cdb905ca8992266fe5b: 8335655: ProblemList serviceability/dcmd/vm tests failing after JDK-8322475
  • 3efa93ba1307cedf05609c0c04b2ba986a515f6e: 8335588: Fix -Wzero-as-null-pointer-constant warnings in calls to Node ctor
  • 587535c5b9bb258836b47c3a8c41ffb91bbfc131: 8334545: runtime/ClassInitErrors/TestStackOverflowDuringInit.java fails after JDK-8294960
  • 68ffec9800b798927a050900a2d47000aa18ef30: 8335479: JFR: Missing documentation for -XX:StartFlightRecording
  • 9a91865ff38f6fbb48b9aba5028e0b529d9bce76: 8335395: G1: Verification does not detect references into Free regions
  • 13b782c3de9a470a7cf1db9d5111ce19faf28729: 8334554: RISC-V: verify & fix perf of string comparison
  • 8aaec37ace102b55ee1387cfd1967ec3ab662083: 8322475: Extend printing for System.map
  • ... and 39 more: https://git.openjdk.org/jdk/compare/53242cdf9ef17c502ebd541e84370e7c158639c1...master

Your commit was automatically rebased without conflicts.

openjdk[bot] avatar Jul 04 '24 08:07 openjdk[bot]

@lahodaj Pushed as commit 3e3f83f62c67caf960ca031439b022f915e1102a.

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

openjdk[bot] avatar Jul 04 '24 08:07 openjdk[bot]