openrewrite / rewrite-spring

OpenRewrite recipes for Spring projects.
Apache License 2.0
253 stars 73 forks source link

Type Information Missing or Malformed in HttpSecurityLambdaDsl Tests #530

Closed ohyesgocool closed 4 months ago

ohyesgocool commented 4 months ago

What version of OpenRewrite are you using?

I am using

How are you running OpenRewrite?

I have added a Java sample test case in the latest openrewrite project. You can find the java version here

And the kotlin version here

What is the smallest, simplest way to reproduce the problem?

you can clone the repo and and run the tests.

What is the full stack trace of any errors you encountered?

java.lang.IllegalStateException: LST contains missing or invalid type information
Identifier->ClassDeclaration->CompilationUnit
/*~~(Identifier type is missing or malformed)~~>*/WebSecurityConfigurerAdapter

MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit
/*~~(MethodInvocation type is missing or malformed)~~>*/http.csrf().disable()
              .antMatcher("/**")
    at org.openrewrite.java.Assertions.assertValidTypes(Assertions.java:87)
    at org.openrewrite.java.Assertions.validateTypes(Assertions.java:57)
    at org.openrewrite.java.Assertions$$Lambda$436/0x0000009801168b30.accept(Unknown Source)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:305)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:133)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:128)
    at org.openrewrite.spring.security6.ApplyToWithLambdaDslTest.testDisableWithSessionManagementAndHttpBasic(ApplyToWithLambdaDslTest.java:318)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:765)

Are you interested in [contributing a fix to OpenRewrite]

Im guessting the problem is caused in this particular class which handles HttpSecurityLambdaDsl.

timtebeek commented 4 months ago

hi! Neat the see the additions you're working on in https://github.com/openrewrite/rewrite-spring/compare/main...freenowtech:rewrite-spring:http-security-lambda-dsl-tests ; appreciate you folks looking to contribute back to the project! πŸ™πŸ»

What's odd here is that you're reporting type issues with a test not modified in your branch πŸ€” org.openrewrite.spring.security6.ApplyToWithLambdaDslTest.testDisableWithSessionManagementAndHttpBasic. Sometimes it helps to run ./gradlew downloadRecipeDependencies locally; could that help you here as well?

PS: for good measure I've triggered the tests on the main branch just to be sure: https://github.com/openrewrite/rewrite-spring/actions/runs/9175673345/job/25229149657

ohyesgocool commented 4 months ago

Hi @timtebeek πŸ‘‹ , thanks for looking into the issue , Sorry that i linked a wrong branch , I have downloaded and tested in local ,

Im running this test in local.

java.lang.IllegalStateException: LST contains missing or invalid type information
Identifier->ClassDeclaration->CompilationUnit
/*~~(Identifier type is missing or malformed)~~>*/WebSecurityConfigurerAdapter

MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->MethodInvocation->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit
/*~~(MethodInvocation type is missing or malformed)~~>*/http.csrf().disable()
              .antMatcher("/**")
    at org.openrewrite.java.Assertions.assertValidTypes(Assertions.java:87)
    at org.openrewrite.java.Assertions.validateTypes(Assertions.java:57)
    at org.openrewrite.java.Assertions$$Lambda$436/0x000000980116d158.accept(Unknown Source)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:305)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:133)
    at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:128)
    at org.openrewrite.spring.security6.ApplyToWithLambdaDslTest.testDisableWithSessionManagementAndHttpBasic(ApplyToWithLambdaDslTest.java:318)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:765)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$221/0x000000980111ac08.apply(Unknown Source)
timtebeek commented 4 months ago

Sure! The text blocks are missing an import, which leads to a missing type, which then throws the above error. We built this check into the testing framework as it leads to a lot of debugging when writing new tests, which should now be easier to troubleshoot.

import org.springframework.security.config.http.SessionCreationPolicy;
timtebeek commented 4 months ago

Can we close this issue @ohyesgocool ? I think we've solved the test issue you had by adding that missing dependency right?

ohyesgocool commented 4 months ago

Hi @timtebeek , thanks for looking into the issue , yes we could close it. i will do it now