openrewrite / openrewrite/rewrite

🐛 Unbounded wildcard in `JavaTemplate` does not match array types

Open
#4,281 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This happens on OpenRewrite 8.28.1

A JavaTemplate string such as #{arg:any(java.util.Map<?,?>)} will not match the argument Map.of("key", new Object[] {1,2,3}) for example.

Workaround

Changing the template string to a raw type will match: #{arg:any(java.util.Map)}.

Refaster recipes generate templates with wildcards so the workaround is hardly viable unless developers manually copy the generated recipes from target to src and modify them accordingly.

Examples
  1. @Test javaTemplateNotMatched_example1
  2. @Test javaTemplateNotMatched_example2

With the accompanying recipe: https://github.com/Philzen/rewrite-TestNG-to-JUnit5/blob/feba2bf03318e2569569d4f71d82efbd467a8c44/src/main/java/org/philzen/oss/GenericsLstIssue.java

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

Start by reproducing the failure in the linked GenericsLstIssueTest.java tests using the GenericsLstIssue.java recipe and the JavaTemplate example from the report. Trace JavaTemplate matching for Map against an array-valued argument, then add regression coverage showing that the wildcard template matches the reported Map.of case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.