openrewrite / openrewrite/rewrite
Parse error in Java parser when using type annotation with varags
Open
Nobody has claimed this yet.
bug
java
parser
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
Used version
rewrite-java 8.56.1
The gist
Object @Nullable ... other is interpreted as Object @Nullable[] ... other
while e.g. the following is interpreted correctly:
Object @Nullable[] ... other
Object ... other
Issue fully replicated in test:
package de.domagoj.or.test;
import static org.openrewrite.java.Assertions.java;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
public class MyTest implements RewriteTest {
@Test
void shouldParse() {
rewriteRun(
java(
"""
package de.domagoj.or.test.example;
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public interface Itf {
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ TYPE_USE })
public @interface NonNull {
}
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ TYPE_USE })
public @interface Nullable {
}
@NonNull
Object exampleMethod(@NonNull Object @Nullable ... other);
}
"""
)
);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the embedded rewriteRun JavaParser reproduction and inspect how the parser handles a type-use annotation before a varargs parameter. Confirm the distinction between Object @Nullable ... other and Object @Nullable[] ... other; done means the supplied test parses the first form without interpreting it as an array annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100