Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk18 Public archive

8278834: Error "Cannot read field "sym" because "this.lvar[od]" is null" when compiling #110

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jan 19, 2022

For code like:

public class TestInstanceOf {

    public static void main(String[] args) {
        Number abc = 1;
        new Object() {
            {
                if (abc instanceof Integer integer) {
                    System.out.println(integer.intValue());
                }
            }
        };
    }

}

javac crashes with:

An exception has occurred in the compiler (17-internal). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://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 "sym" because "this.lvar[3]" is null
        at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:577)
        at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.load(Items.java:399)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:902)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitNewClass(Gen.java:1961)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1852)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1742)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:645)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:631)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:682)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1097)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:645)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:967)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:930)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
        at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2414)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:737)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1617)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1585)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

The cause is in TransPatterns - it tracks the current class and method, so that it can define correct owners for temporary variables. But if there's a class nested in a method, the current method field is not cleared, and consequently the temporary variables get a wrong owner (the method enclosing the class, not a method inside the current class), which then crashes subsequent phases, like Gen.

The proposed fix is to clear currentMethod when entering a class AST node.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8278834: Error "Cannot read field "sym" because "this.lvar[od]" is null" when compiling

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk18 pull/110/head:pull/110
$ git checkout pull/110

Update a local copy of the PR:
$ git checkout pull/110
$ git pull https://git.openjdk.java.net/jdk18 pull/110/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 110

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk18/pull/110.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 19, 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 Jan 19, 2022
@openjdk
Copy link

openjdk bot commented Jan 19, 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.java.net label Jan 19, 2022
@mlbridge
Copy link

mlbridge bot commented Jan 19, 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 Jan 19, 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:

8278834: Error "Cannot read field "sym" because "this.lvar[od]" is null" when compiling

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Jan 19, 2022
@lahodaj
Copy link
Contributor Author

lahodaj commented Jan 19, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Jan 19, 2022

Going to push as commit be0538d.
Since your change was applied there has been 1 commit pushed to the master branch:

  • f5de6fa: 8272058: 25 Null pointer dereference defect groups in 4 files

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 19, 2022

@lahodaj Pushed as commit be0538d.

💡 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.java.net integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants