-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
👋 Welcome back winterhalter! A progress list of the required criteria for merging this PR into |
Webrevs
|
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. |
49cd2c4
to
ac30616
Compare
Thanks, I had those working on Mercurial and kind of winged the transfer Should work now! |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { } | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -89,6 +90,26 @@ public static CoreReflectionFactory make(GenericDeclaration d, Scope s) { | |||
return new CoreReflectionFactory(d, s); | |||
} | |||
|
|||
public static Type ownerType(Class<?> c) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cc60c45
to
811afcb
Compare
There was a problem hiding this 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.
@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:
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
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 |
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.
Rebased on HEAD/master. |
Tier 1-3 looks good, go ahead and / integrate and I'll sponsor |
/integrate |
/sponsor |
@jbf @raphw Since your change was applied there have been 21 commits pushed to the
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. |
…s type variables Reviewed-by: jfranck
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
Testing
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/851/head:pull/851
$ git checkout pull/851