Skip to content

Parse error in Java parser when using type annotation with varags #5742

@domagojcc

Description

@domagojcc

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);
}
                    """
                )
            );
        }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions