openrewrite / openrewrite/rewrite

🐛 Tests involving Map with unbounded wildcards throw LST error

Open
#4,280 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

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

https://github.com/openrewrite/rewrite/blob/0c7f396a42c7f43c40f2d35186736829a76f1c7c/rewrite-java-test/src/test/java/org/openrewrite/java/format/MethodParamPadTest.java#L333

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the three linked examples and inspect the final org.openrewrite.java.Assertions.assertValidTypes check, comparing it with the RewriteTest#defaults() workaround referenced from MethodParamPadTest.java. Trace why MethodInvocation type information is missing for unbounded wildcard Map arguments, then add a regression test showing the examples pass without disabling validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.