openrewrite / rewrite

Automated mass refactoring of source code.

Home Page:https://docs.openrewrite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Tests involving Map with unbounded wildcards throw LST error

Philzen opened this issue Β· comments

This happens on OpenRewrite 8.28.1

rewriteRun-tests on a recipe that rewrites J.MethodInvocation arguments of type Map<?, ?> throw

java.lang.IllegalStateException: LST contains missing or invalid type information
MethodInvocation->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit
/*~~(MethodInvocation type is missing or malformed)~~>*/SomeClassWithGenericMethod.someSimilarMethod(map)

for now apparent reason 🀷 – the recipe can be built, installed and run against existing code fine.

This happens on a final pass at org.openrewrite.java.Assertions.assertValidTypes after the before/after assertion has passed – if it doesn't, the tests fail as usual with the diff.

Example

I have assembled the most minimal example was able to unpack here:

  1. lstError_example1_methodInvocationType
  2. lstError_example2_methodInvocationType
  3. lstError_example3_methodInvocationType

With the accompanying Recipe GenericsLstIssue

This may happen with other unbounded wildcard types, needs further investigation.

Workaround

Configuring the RewriteTest#defaults() with

spec -> spec.typeValidationOptions(TypeValidation.none()),

disables the final check which apparently triggers this warning (thanks @knutwannheden for pointing this out).