rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Wrong declaring type on JavaTemplate generated method type

Open BoykoAlex opened this issue 2 years ago • 2 comments

Unit test for #3573

BoykoAlex avatar Sep 28 '23 21:09 BoykoAlex

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)

timtebeek avatar Sep 29 '23 07:09 timtebeek

Without having looked at the JavaTemplate internals this seems like an oversight indeed, with potential negative effects for downstream recipes.

timtebeek avatar Sep 29 '23 08:09 timtebeek