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

8202471: (ann) Cannot read type annotations on generic receiver type's type variables #851

Closed
wants to merge 1 commit into from

Conversation

raphw
Copy link
Member

@raphw raphw commented Oct 24, 2020

A method's or constructor's owner type might carry annotations on its potential type parameters but is never represented as parameterized type what makes these parameters inaccessible at runtime, despite the presence of parameter type annotations.


Progress

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

Testing

Linux aarch64 Linux arm Linux ppc64le Linux s390x Linux x64 Linux x86 Windows x64 macOS x64
Build ✔️ (1/1 passed) ✔️ (1/1 passed) ✔️ (1/1 passed) ✔️ (1/1 passed) ✔️ (5/5 passed) ✔️ (2/2 passed) ✔️ (2/2 passed) ✔️ (2/2 passed)
Test (tier1) ✔️ (9/9 passed) ✔️ (9/9 passed) ✔️ (9/9 passed) ✔️ (9/9 passed)

Issue

  • JDK-8202471: (ann) Cannot read type annotations on generic receiver type's type variables

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/851/head:pull/851
$ git checkout pull/851

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 24, 2020

👋 Welcome back winterhalter! 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 Oct 24, 2020
@openjdk
Copy link

openjdk bot commented Oct 24, 2020

@raphw The following label will be automatically applied to this pull request:

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Oct 24, 2020
@mlbridge
Copy link

mlbridge bot commented Oct 24, 2020

Webrevs

@shipilev
Copy link
Member

Hint: if you merge from master, you would get the updated test workflows, which would include the artifact with *.jtr (jtreg output) files in "testsupport". You can then use them to diagnose the testing failures you are getting.

@raphw raphw force-pushed the 8202471 branch 3 times, most recently from 49cd2c4 to ac30616 Compare October 31, 2020 21:06
@raphw
Copy link
Member Author

raphw commented Nov 1, 2020

Thanks, I had those working on Mercurial and kind of winged the transfer Should work now!

Copy link
Member

@jbf jbf left a comment

Choose a reason for hiding this comment

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

Hi Rafael,

Thanks for your patience and for the patch, I left a few comments.

Type o = resolveOwner(enclosingClass);
Type t;
if (o != null || v.length > 0) {
t = ParameterizedTypeImpl.make(enclosingClass, v, o);
Copy link
Member

Choose a reason for hiding this comment

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

I think these should be instantiated by a GenericsFactory. Ideally you shouldn't have to import the reflective object directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it to the existing generics factory but as a static method since the instance values are not really required.

@@ -656,13 +657,22 @@ public AnnotatedType getAnnotatedReceiverType() {
return null;
}

TypeVariable<?>[] v = enclosingClass.getTypeParameters();
Copy link
Member

Choose a reason for hiding this comment

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

Can you push down most or all of this to resolveOwner? It can then either return a Class instance or an appropriate Type instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed it down to the factory.

return null;
}
Class<?> c = getDeclaringClass();
TypeVariable<?>[] v = c.getTypeParameters();
Copy link
Member

Choose a reason for hiding this comment

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

Same here, can this be pushed down to a common method that either returns a Class or resolves the appropriate Type instance?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved it to an annotation factory class and avoided the import.

class Inner {
Inner(TestReceiverTypeParameterizedConstructor<@TypeAnnotation T> TestReceiverTypeParameterizedConstructor.this) { }
}

Copy link
Member

Choose a reason for hiding this comment

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

It might be good to add a case where the annotated type variable isn't on the immediate outer type like:

    class Inner2 {
        class  TwiceInner {
            TwiceInner(TestReceiverTypeParameterizedConstructor<@TypeAnnotation T>.Inner2 TestReceiverTypeParameterizedConstructor.Inner2.this) { }
        }
    }

Same for the method test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added two tests for it.

@raphw raphw changed the title 8202471: Make type annotations on owner type parameters available 8202471: (ann) Cannot read type annotations on generic receiver type's type variables Nov 15, 2020
@@ -89,6 +90,26 @@ public static CoreReflectionFactory make(GenericDeclaration d, Scope s) {
return new CoreReflectionFactory(d, s);
}

public static Type ownerType(Class<?> c) {
Copy link
Member

Choose a reason for hiding this comment

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

This feels somewhat odd. How about, moving these back to Executable and rename ownerType to resolveToType ? I realise we can't get use getFactory() in executable but as you write, it isn't needed, it should be fine in this case to create it directly as in your v1. The reason is the semantics of this is somewhat unintuitive and is only used in the annotated receiver case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the code back and it's fairly compact now. I added "owner" to the method name since it does not make sense otherwise. Let me know what you think!

import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Constructor;

public class TestReceiverTypeParameterizedConstructorNested {
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion, what I would like to test is that we can walk up the chain and find type parameters on the outermost owner. Same for Method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I adjusted the test to check for an inner and outer variable for both method and constructor.

@raphw raphw force-pushed the 8202471 branch 2 times, most recently from cc60c45 to 811afcb Compare November 16, 2020 11:06
Copy link
Member

@jbf jbf 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. I'll run some additional testing on the patch.

@openjdk
Copy link

openjdk bot commented Nov 16, 2020

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

8202471: (ann) Cannot read type annotations on generic receiver type's type variables

Reviewed-by: jfranck

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

  • 6d87856: 8256325: Remove duplicate asserts in PhaseMacroExpand::expand_macro_nodes
  • 5dbfae0: 8255058: C1: assert(is_virtual()) failed: type check
  • 4553fa0: 8256258: some missing NULL checks or asserts after CodeCache::find_blob_unsafe
  • 1228517: 8256274: C2: Optimize copying of the shared type dictionary
  • 537b40e: 8252588: HotSpot Style Guide should permit uniform initialization
  • c35e1a2: 8255947: [macos] Signed macOS jpackage app doesn't filter spurious '-psn' argument
  • 30a2ad5: 8254872: Optimize Rotate on AArch64
  • eabf3ba: 8256037: [TESTBUG] com/sun/jndi/dns/ConfigTests/PortUnreachable.java fails due to the hard coded threshold is small
  • 36dbe6f: 8256376: The javax/swing/JSpinner/SerializationTest.java fails on headful windows
  • bf84dac: 8247781: Day periods support
  • ... and 9 more: https://git.openjdk.java.net/jdk/compare/8eeb36f14a9121b6cb1ed3228f78021d5da9e81b...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jbf) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 16, 2020
@jbf
Copy link
Member

jbf commented Nov 16, 2020

I think it would be good to rebase on top of a recent jdk upstream before merging.

…ns on its potential type parameters but is never represented as parameterized type what makes these parameters inaccessible at runtime, despite the presence of parameter type annotations.
@raphw
Copy link
Member Author

raphw commented Nov 16, 2020

Rebased on HEAD/master.

@jbf
Copy link
Member

jbf commented Nov 17, 2020

Tier 1-3 looks good, go ahead and / integrate and I'll sponsor

@raphw
Copy link
Member Author

raphw commented Nov 17, 2020

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Nov 17, 2020
@openjdk
Copy link

openjdk bot commented Nov 17, 2020

@raphw
Your change (at version 91c518c) is now ready to be sponsored by a Committer.

@jbf
Copy link
Member

jbf commented Nov 17, 2020

/sponsor

@openjdk openjdk bot closed this Nov 17, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 17, 2020
@openjdk
Copy link

openjdk bot commented Nov 17, 2020

@jbf @raphw Since your change was applied there have been 21 commits pushed to the master branch:

  • adb8561: 8253228: [JVMCI] provide more info on fatal JVMCI errors
  • a7422ac: 8255150: Add utility methods to check long indexes and ranges
  • 6d87856: 8256325: Remove duplicate asserts in PhaseMacroExpand::expand_macro_nodes
  • 5dbfae0: 8255058: C1: assert(is_virtual()) failed: type check
  • 4553fa0: 8256258: some missing NULL checks or asserts after CodeCache::find_blob_unsafe
  • 1228517: 8256274: C2: Optimize copying of the shared type dictionary
  • 537b40e: 8252588: HotSpot Style Guide should permit uniform initialization
  • c35e1a2: 8255947: [macos] Signed macOS jpackage app doesn't filter spurious '-psn' argument
  • 30a2ad5: 8254872: Optimize Rotate on AArch64
  • eabf3ba: 8256037: [TESTBUG] com/sun/jndi/dns/ConfigTests/PortUnreachable.java fails due to the hard coded threshold is small
  • ... and 11 more: https://git.openjdk.java.net/jdk/compare/8eeb36f14a9121b6cb1ed3228f78021d5da9e81b...master

Your commit was automatically rebased without conflicts.

Pushed as commit 53a3188.

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

openjdk-notifier bot referenced this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants