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

8345944: JEP 492: extending local class in a different static context should not be allowed #22679

Closed
wants to merge 2 commits into from

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Dec 11, 2024

This PR fixes a couple of issues associated with the implementation of the new stricter checks for local class creation defined by JEP 492.
There are two issues:

  • the new checks do not apply to all local classes, especially those whose owner happens to be a variable;
  • the new checks do not apply when a class extends a local class -- that's because javac only checks superclasses in the case the superclass is an inner class

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

Issues

  • JDK-8345944: JEP 492: extending local class in a different static context should not be allowed (Bug - P3)(⚠️ The fixVersion in this issue is [24] but the fixVersion in .jcheck/conf is 25, a new backport will be created when this pr is integrated.)
  • JDK-8345953: JEP 492: instantiating local classes in a different static context should not be allowed (Bug - P3)(⚠️ The fixVersion in this issue is [24] but the fixVersion in .jcheck/conf is 25, a new backport will be created when this pr is integrated.)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22679

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 11, 2024

👋 Welcome back mcimadamore! 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.

}
} else if (tree.meth.hasTag(SELECT)) {
log.error(tree.meth.pos(),
Errors.IllegalQualNotIcls(site.tsym));
attribExpr(((JCFieldAccess) tree.meth).selected, localEnv, site);
}

if (tree.meth.hasTag(IDENT)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved this code outside the if (encl != null) so that now it can be applied to all kind of superclasses. Note that checkNewInnerClass will also check whether the target class is either inner or local, so we don't need to check anything else here.

@openjdk
Copy link

openjdk bot commented Dec 11, 2024

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

8345944: JEP 492: extending local class in a different static context should not be allowed
8345953: JEP 492: instantiating local classes in a different static context should not be allowed

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

  • d381d58: 8332268: C2: Add missing optimizations for UDivI/L and UModI/L and unify the shared logic with the signed nodes
  • 45c914c: 8343607: C2: Shenandoah crashes during barrier expansion in Continuation::enter
  • a21d21f: 8345609: [C1] LIR Operations with one input should be implemented as LIR_Op1
  • 2382a2d: 8345661: Simplify page size alignment in code heap reservation
  • 076bfa6: 8345656: Move os alignment functions out of ReservedSpace
  • 2826838: 8345658: WB_NMTCommitMemory redundantly records an NMT tag
  • c9ec271: 8345800: Update copyright year to 2024 for serviceability in files where it was missed
  • 8e0f929: 8345805: Update copyright year to 2024 for other files where it was missed
  • f88c1c6: 8345773: Class-File API debug printing capability
  • e88e793: 8343148: C2: Refactor uses of "PhaseValue::con() + PhaseIdealLoop::set_ctrl()" into separate method
  • ... and 118 more: https://git.openjdk.org/jdk/compare/4000e923e8b4472fe022f1fd78a1c42b2045683f...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
Copy link

openjdk bot commented Dec 11, 2024

@mcimadamore 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 11, 2024
@@ -3065,7 +3070,7 @@ public void report(DiagnosticPosition _unused, JCDiagnostic details) {
}

void checkNewInnerClass(DiagnosticPosition pos, Env<AttrContext> env, Type type, boolean isSuper) {
boolean isLocal = type.tsym.owner.kind == MTH;
boolean isLocal = type.tsym.owner.kind == VAR || type.tsym.owner.kind == MTH;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most local classes will have their owner set to some method symbols. But, in some corner cases where a local class is defined inside a field initializer, the owner can actually be a variable symbol too.

@@ -3834,7 +3834,7 @@ Symbol findSelfContaining(DiagnosticPosition pos,
*/
Symbol findLocalClassOwner(Env<AttrContext> env, TypeSymbol c) {
Symbol owner = c.owner;
Assert.check(owner.kind == MTH);
Assert.check(owner.kind == MTH || owner.kind == VAR);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now need to generalize this, so that it works for both method and variable owners.

@mcimadamore mcimadamore changed the title JEP 492: extending local class in a different static context should not be allowed 8345944: JEP 492: extending local class in a different static context should not be allowed Dec 11, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 11, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 11, 2024

Webrevs

@mcimadamore
Copy link
Contributor Author

/solves 8345953

@openjdk
Copy link

openjdk bot commented Dec 11, 2024

@mcimadamore
Adding additional issue to solves list: 8345953: JEP 492: instantiating local classes in a different static context should not be allowed.

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.

lgtm

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 11, 2024
@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 12, 2024

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

  • 68aa4d4: 8346063: java/lang/Thread/virtual/Starvation.java missing @requires vm.continuations
  • 77e4932: 8344026: Ubsan: prevent potential integer overflow in c1_LIRGenerator_.cpp file
  • 3f2556b: 8345984: Remove redundant checkXXX methods from java.management Util class
  • ceb4366: 8345955: Deprecate the UseOprofile flag with a view to removing the legacy oprofile support in the VM
  • 72c59de: 8345876: Update nativeAddAtIndex comment to match the code
  • 75cfb64: 8310691: [REDO] [vectorapi] Refactor VectorShuffle implementation
  • 4da6fd4: 8345423: Shenandoah: Parallelize concurrent cleanup
  • ec219ae: 8346039: [BACKOUT] - [C1] LIR Operations with one input should be implemented as LIR_Op1
  • 05c5678: 8345959: Make JVM_IsStaticallyLinked JVM_LEAF
  • 64fad1c: 8345797: Update copyright year to 2024 for client-libs in files where it was missed
  • ... and 139 more: https://git.openjdk.org/jdk/compare/4000e923e8b4472fe022f1fd78a1c42b2045683f...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 12, 2024

@mcimadamore Pushed as commit 0ad6423.

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

@mcimadamore
Copy link
Contributor Author

mcimadamore commented Dec 12, 2024

/backport :jdk24

@openjdk
Copy link

openjdk bot commented Dec 12, 2024

@mcimadamore The target repository jdk24 is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk21u, openjdk/jdk21u-dev, openjdk/jdk23u, openjdk/jdk24u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/jfx, openjdk/jfx17u, openjdk/jfx21u, openjdk/jfx23u, openjdk/lilliput-jdk17u, openjdk/lilliput-jdk21u, openjdk/shenandoah-jdk21u, openjdk/shenandoah-jdk8u.
Supplying the organization/group prefix is optional.

There is a branch jdk24 in the current repository openjdk/jdk.
To target a backport to this branch in the current repository use:
/backport :jdk24

@mcimadamore
Copy link
Contributor Author

/backport :jdk24

@openjdk
Copy link

openjdk bot commented Dec 12, 2024

@mcimadamore the backport was successfully created on the branch backport-mcimadamore-0ad64234-jdk24 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk24, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 0ad64234 from the openjdk/jdk repository.

The commit being backported was authored by Maurizio Cimadamore on 12 Dec 2024 and was reviewed by Vicente Romero.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk:

$ git fetch https://github.com/openjdk-bots/jdk.git backport-mcimadamore-0ad64234-jdk24:backport-mcimadamore-0ad64234-jdk24
$ git checkout backport-mcimadamore-0ad64234-jdk24
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk.git backport-mcimadamore-0ad64234-jdk24

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.

2 participants