Skip to content

Java Parser might fail when array brackets [] come after method parameters #6398

@greg-at-moderne

Description

@greg-at-moderne

What version of OpenRewrite are you using?

Current main = cc34e75

What is the smallest, simplest way to reproduce the problem?

TIL this is valid Java syntax.

The following test when added to JavaParserTest:

    @Test
    void cstyleArrayMethod() {
        rewriteRun(
          // language=java
          java(
            """
            class A {    
                public byte toByteArray()[] {
                  return new byte[]{};
                }
            }
            """
          )
        );
    }

fails with:

org.opentest4j.AssertionFailedError: [When parsing and printing the source code back to text without modifications, the printed source didn't match the original source code. This means there is a bug in the parser implementation itself. Please open an issue to report this, providing a sample of the code that generated this error. "A.java":
 class A {
-    public byte toByteArray()[] {
+    public byte toByteArray()[]toByteArray() {
       return new byte[]{};
     }
 }

OSS repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjavaparsertest providedAlready replicated with a unit test, using JUnit pioneer's ExpectedToFail

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions