[
https://issues.apache.org/jira/browse/GROOVY-10761?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles closed GROOVY-10761.
--------------------------------
Resolution: Information Provided
> MethodNode won't accept ClassNode with generics as return type
> --------------------------------------------------------------
>
> Key: GROOVY-10761
> URL: https://issues.apache.org/jira/browse/GROOVY-10761
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.5
> Reporter: Christopher Smith
> Priority: Major
>
> This is likely a case of "there's a specific idiomatic way to make this
> work", but the overall API documentation suggests that this case _should_
> work. I have a base class with a generic property:
> {code}
> class Base<M> {
> M meta
> }
> {code}
> In an ASTT, I attempt to create this derived class:
> {code}
> class Derived extends Base<Map<String, Object>> {
> final Map<String, Object> getMeta() { super.getMeta() }
> final void setMeta(Map<String, Object> value) { super.setMeta(value) }
> }
> {code}
> I am trying to create the {{getMeta}} method as follows:
> {code}
> derivedCn.addMethod(new MethodNode(
> 'getMeta',
> PUBLIC | FINAL,
> makeClassSafeWithGenerics(makeWithoutCaching(Map),
> STRING_TYPE.asGenericsType(), OBJECT_TYPE.asGenericsType()),
> Parameter.EMPTY_ARRAY,
> ClassNode.EMPTY_ARRAY,
> returnS(callSuperX(name))
> ))
> {code}
> In particular, I'm following the "official" format for creating a
> {{ClassNode}} representing {{Map<String, Object>}}. However, I still receive
> the compiler error
> {code}
> A transform used a generics containing ClassNode
> java.util.Map<java.lang.String, java.lang.Object> for the method public final
> java.util.Map<java.lang.String, java.lang.Object> getMeta() { ... } directly.
> You are not supposed to do this. Please create a new ClassNode referring to
> the old ClassNode and use the new ClassNode instead of the old one. Otherwise
> the compiler will create wrong descriptors and a potential
> NullPointerException in TypeResolver in the OpenJDK. If this is not your own
> doing, please report this bug to the writer of the transform.
> {code}
> I observe that {{MethodNode}} defines a property {{genericsTypes}}, but in
> this case the method itself is not generic, it simply has a (non-generic)
> return type that is itself generic.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)