rewrite
rewrite copied to clipboard
Wrong declaring type on JavaTemplate generated method type
Unit test for #3573
Thanks for reporting the issue and highlighting it with a failing test! Here's the test failures copied to save a click:
JavaTemplateTest > JavaTemplate should add a method with the declaring type == the type of declaring class type FAILED
org.opentest4j.AssertionFailedError:
expected: AClass
but was: Template
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at [email protected]/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at app//org.openrewrite.java.JavaTemplateTest.javaTemplateShouldAssignDeclaringTypesProperly_1(JavaTemplateTest.java:1084)
JavaTemplateTest > JavaTemplate should add a method with the declaring type == the type of declaring class type FAILED
org.opentest4j.AssertionFailedError:
expected: AClass
but was: Template
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at [email protected]/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at app//org.openrewrite.java.JavaTemplateTest.javaTemplateShouldAssignDeclaringTypesProperly_2(JavaTemplateTest.java:1127)
Without having looked at the JavaTemplate internals this seems like an oversight indeed, with potential negative effects for downstream recipes.