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

8346751: Internal java compiler error with type annotations in constants expression in constant fields #23029

Closed
wants to merge 2 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jan 10, 2025

Consider code like:

import java.lang.annotation.*;
public class Decl {
    String VALUE = (@Nullable String) "";
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE })
@interface Nullable {}

When processing this code, when Attr.visitVarDef is called for the field, it will first call Annotate.queueScanTreeAndTypeAnnotate on the initializer expression, which will find and attribute type annotations. Then the initializer is attributed, and eventually Annotate.annotateTypeSecondStage is called on the annotated type (@Nullable String). This second stage depends on the type annotations being already attributed. This works OK.

The problem appears when the code like changed to be like:

import java.lang.annotation.*;
@SuppressWarnings(Decl.VALUE)
public class Decl {
    public static final @Nullable String VALUE = (@Nullable String) "";
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE })
@interface Nullable {}

In this code, the field is a constant, and it is used from the annotation before Attr.visitVarDef is called on the constant. This will trigger attribution of the constant initializer (Attr.attribLazyConstantValue), which will trigger the Annotate.annotateTypeSecondStage on the annotated type, but Annotate.queueScanTreeAndTypeAnnotate was not yet called on the initializer, and so the type annotations are not attributed yet, and javac crashes with an exception like:

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.checkNonNull(Assert.java:62)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.fromAnnotations(Annotate.java:167)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateTypeSecondStage$0(Annotate.java:1065)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:194)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:157)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1820)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1080)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:949)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
...

The proposed solution herein is to make sure Annotate.queueScanTreeAndTypeAnnotate is called before attributing field initializers in Attr.attribLazyConstantValue. A flag is used to make sure it is invoked at most once per field.


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-8346751: Internal java compiler error with type annotations in constants expression in constant fields (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23029

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

Using diff file

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

Using Webrev

Link to Webrev Comment

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 10, 2025

👋 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
Copy link

openjdk bot commented Jan 10, 2025

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

8346751: Internal java compiler error with type annotations in constants expression in constant fields

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

  • 062f2dc: 8347554: [BACKOUT] C2: implement optimization for series of Add of unique value
  • a289bcf: 8306579: Consider building with /Zc:throwingNew
  • cede304: 8347482: Remove unused field in ParkEvent
  • fa5ff82: 8342062: Reformat keytool and jarsigner output for keys with a named parameter set
  • cc19897: 8293123: Fix various include file ordering
  • 6e43f48: 8346929: runtime/ClassUnload/DictionaryDependsTest.java fails with "Test failed: should be unloaded"
  • c885e59: 8346377: Properly support static builds for Windows
  • 0612636: 8347373: HTTP/2 flow control checks may count unprocessed data twice
  • 450636a: 8347274: Gatherers.mapConcurrent exhibits undesired behavior under variable delays, interruption, and finishing
  • 82e2a79: 8347006: LoadRangeNode floats above array guard in arraycopy intrinsic
  • ... and 112 more: https://git.openjdk.org/jdk/compare/f1d85ab3e61f923b4e120cf30e16109e04505b53...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 rfr Pull request is ready for review label Jan 10, 2025
@openjdk
Copy link

openjdk bot commented Jan 10, 2025

@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 Jan 10, 2025
@mlbridge
Copy link

mlbridge bot commented Jan 10, 2025

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

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 13, 2025
@lahodaj
Copy link
Contributor Author

lahodaj commented Jan 24, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Jan 24, 2025

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

  • 2daafe4: 8348283: java.lang.classfile.components.snippets.PackageSnippets shipped in java.base.jmod
  • 50ca450: 8340784: Remove PassFailJFrame constructor with screenshots
  • 416d469: 8347008: beancontext package spec does not clearly explain why the API is deprecated
  • 471d63c: 8343609: Broken links in java.xml
  • 7f16a08: 8348240: Remove SystemDictionaryShared::lookup_super_for_unregistered_class()
  • 48ece07: 8282862: AwtWindow::SetIconData leaks old icon handles if an exception is detected
  • 356e2a8: 8348406: Remove tests GrantAllPermToExtWhenNoPolicy and PrincipalExpansionError from problem list
  • 3ebf889: 8348327: Incorrect march flag when building libsleef/vector_math_neon.c
  • d9d2e19: 8348365: Bad format string in CLDRDisplayNamesTest
  • 59e7509: 8348301: Remove unused Reference.waitForReferenceProcessing break-ins in tests
  • ... and 288 more: https://git.openjdk.org/jdk/compare/f1d85ab3e61f923b4e120cf30e16109e04505b53...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 24, 2025

@lahodaj Pushed as commit 0395593.

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

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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants