Skip to content
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

8292756: java.lang.AssertionError at at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386) #10347

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Sep 19, 2022

Consider code like:

public class JDK_8292756 {
    private int test(Object o) {
        int i1, i2, i3, i4, i5, i6, i7;
        return switch(o) {
            case Object oo when oo != null -> 0;
            default -> 0;
        };
    }
}

Compiling this leads to a crash:

$ javac --enable-preview -source 19 /tmp/JDK_8292756.java 
Note: /tmp/JDK_8292756.java uses preview features of Java SE 19.
Note: Recompile with -Xlint:preview for details.
An exception has occurred in the compiler (19-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.AssertionError
        at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
        at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
        at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1465)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1253)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5621)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5512)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5336)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5275)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
        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)
printing javac parameters to: /tmp/javac.20220919_200140.args

The reason for the failure is this: in Attr.handleSwitch, there is an input scope env, and a sub-scope of it, switchEnv, is created for the switch. Eventually, another (shared) sub-scope is created for the guard expression, bodyEnv. All env, switchEnv and bodyEnv share an internal table. But, the bodyEnv sub-scope is created from env, not from switchEnv (as it should). Which mostly works, but if the internal table for bodyEnv is resized, it will correctly fix only env, but not switchEnv.

The solution to this problem is to simply base the bodyEnv on switchEnv, not on env. But, in addition to that, it does not seem right the scopes don't protect from an accident like this. So the proposed patch here is enhancing the assertions in Scope so that a shared duplicate of a Scope can only be done from a leaf Scope.


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-8292756: java.lang.AssertionError at at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10347

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

Using diff file

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

…vac.code.Scope$ScopeImpl.leave(Scope.java:386)
@bridgekeeper
Copy link

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

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

mlbridge bot commented Sep 19, 2022

Webrevs

Copy link
Contributor

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

*/
private int shared;
private boolean shared;
Copy link
Contributor

Choose a reason for hiding this comment

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

great!

@openjdk
Copy link

openjdk bot commented Sep 21, 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:

8292756: java.lang.AssertionError at at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)

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

  • e195897: 8294068: Unconditional and eager load of nio library since JDK-8264744
  • 84d7ff6: 8288129: Shenandoah: Skynet test crashed with iu + aggressive
  • 07afa3f: 8294110: compiler/uncommontrap/Decompile.java fails after JDK-8293798
  • 0746bcb: 8294083: RISC-V: Minimal build failed with --disable-precompiled-headers
  • 95ec2ea: 8293897: Synthetic final modifier is part of the AST for a try-with-resource resource
  • d14e96d: 8293493: Signal Handlers printout should show signal block state
  • da4fdfb: 8293659: Improve UnsatisfiedLinkError error message to include dlopen error details
  • cd1cdcd: 8293116: Incremental JDK build could be sped up
  • e9401e6: 8293364: IGV: Refactor Action in EditorTopComponent and fix minor bugs
  • 844a95b: 8292892: Javadoc index descriptions are not deterministic
  • ... and 81 more: https://git.openjdk.org/jdk/compare/7f3250d71c4866a64eb73f52140c669fe90f122f...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 openjdk bot added the ready Pull request is ready to be integrated label Sep 21, 2022
@lahodaj
Copy link
Contributor Author

lahodaj commented Sep 22, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Sep 22, 2022

Going to push as commit 0be2b2c.
Since your change was applied there have been 107 commits pushed to the master branch:

  • bc2af47: 8254711: Add java.security.Provider.getService JFR Event
  • d781ab0: 8294003: Don't handle si_addr == 0 && si_code == SI_KERNEL SIGSEGVs
  • a216960: 8294087: RISC-V: RVC: Fix a potential alignment issue and add more alignment assertions for the patchable calls/nops
  • 3fa6778: 8292296: Use multiple threads to process ParallelGC deferred updates
  • 800e68d: 8292044: HttpClient doesn't handle 102 or 103 properly
  • 83abfa5: 8255670: Improve C2's detection of modified nodes
  • 5652030: 8292376: A few Swing methods use inheritDoc on exceptions which are not inherited
  • 03f287d: 8293995: Problem list sun/tools/jstatd/TestJstatdRmiPort.java on all platforms because of 8293577
  • d5bee4a: 8294086: RISC-V: Cleanup InstructionMark usages in the backend
  • 47f233a: 8292202: modules_do is called without Module_lock
  • ... and 97 more: https://git.openjdk.org/jdk/compare/7f3250d71c4866a64eb73f52140c669fe90f122f...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 22, 2022

@lahodaj Pushed as commit 0be2b2c.

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

@ice1000
Copy link

ice1000 commented Sep 24, 2022

Any chance this can be backported to JDK 19?

@ice1000
Copy link

ice1000 commented Sep 24, 2022

Several benefits of backporting to JDK 19:

  • Build tools like Gradle wouldn't support JDK 20 until GA, so having a serious bug in JDK 19 = having a JDK 19 without record patterns at all.
  • Users won't be able to extensively test the feature without being able to use the feature. Preview features are supposed to be tested.
  • Bug-fix updates are supposed to deliver bug-fixes, and this is a bug-fix.

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