Skip to content

8357653: Inner classes of type parameters emitted as raw types in signatures #25451

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

biboudis
Copy link
Member

@biboudis biboudis commented May 26, 2025

In the following example, G.Getter is erroneously treated as a raw type by javac:

static abstract class Getters<X> {
  abstract class Getter {
      abstract X get();
  }
}

static class Usage1<T, G extends Getters<T>> {
  public T test(G.Getter getter) {
      return getter.get();
  }
}

The (now reverted) #25346 attempted to fix this by skipping type variables in the calculation of allparams().

While that seemed to fix the type checking error, it was a fragile solution in a number of ways.

  • allparams() is passed to a method that calculates substitutions. This signals that the method adheres to invariants during substitutions where lists of type parameters are expected to be of the same length (for the from and to parts). Affecting directly the allparams_field seems not the right approach.
  • Another observation (thx @liach) was that in the generated bytecode, the fully qualified type of the inner class G still appeared as if it originated from a raw type. assembleClassSig independently examines outer to detect whether it is raw or not.
  • Finally, there is already a proper area in javac, earlier in the pipeline, where javac handles/detects "rare types" (test/langtools/tools/javac/generics/rare): That method is checkId and specifically checkIdInternal. While in the general case the type of an identifier is the symbol's type, checkIdInternal computes a new type in two occasions. In one of those occasions, checkIdInternal is computing the type when the symbol's type is an inner class. Here, we can start normalizing (by skipping the type variables).

Moreover, it has been observed that asEnclosingSuper is a generalization of asOuterSuper and additionally the former is used only in checkIdInternal. As a result, this PR performs two simplifications:

As a first simplification this PR replaces asOuterSuper with asEnclosingSuper.
As a second simplification this PR relies only on the owner's enclClass() based on the following subsequent observations:

  • An enclosingType() call returns the outer_field directly and Type.noType otherwise (in the case of an inner class it refers to the type of its enclosing instance class.)
  • An enclClass() call returns the closest enclosing class and the behavior in asEnclosingSuper containing a loop with the condition t.hasTag(CLASS) combined with asSuper(t, sym) is believed to be the same.

The test now includes bytecode tests additionally to the reflection-based reproducer and the original test case.

// edit: this PR does not perform this simplification and retains asOuterSuper.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change requires CSR request JDK-8359213 to be approved
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8357653: Inner classes of type parameters emitted as raw types in signatures (Bug - P4)
  • JDK-8359213: Inner classes of type parameters emitted as raw types in signatures (CSR)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25451

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 26, 2025

👋 Welcome back abimpoudis! 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 May 26, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented May 26, 2025

@biboudis 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.

@biboudis
Copy link
Member Author

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label May 26, 2025
@openjdk
Copy link

openjdk bot commented May 26, 2025

@biboudis has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@biboudis please create a CSR request for issue JDK-8357653 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@biboudis
Copy link
Member Author

/contributor add @mcimadamore

@openjdk
Copy link

openjdk bot commented May 26, 2025

@biboudis
Contributor Maurizio Cimadamore <[email protected]> successfully added.

@biboudis biboudis marked this pull request as ready for review May 26, 2025 16:06
@openjdk openjdk bot added the rfr Pull request is ready for review label May 26, 2025
@mlbridge
Copy link

mlbridge bot commented May 26, 2025

Webrevs

@mcimadamore
Copy link
Contributor

Looks good - I'm unsure whether we should unify the two routines as part of this fix, or if we wanna keep that for a separate PR (given that might be a potential extra risk)

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 sensible to me

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler [email protected] csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants