rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Parser: not idempotent on annotated varargs

Open Bananeweizen opened this issue 1 year ago • 6 comments

What version of OpenRewrite are you using?

I am using

  • Maven/Gradle plugin v5.17.1

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

class ParserError {
    private String method(@NonNull final String @NonNull... args) {
        return "";
    }
}

What is the full stack trace of any errors you encountered?

java.lang.IllegalStateException: ParserError.java is not print idempotent.
(several lines removed)
-    private String method(@NonNull final String @NonNull... args) {
+    private String method(@NonNull final String[] @NonNull... args) {
         return "";
     }
 
  org.openrewrite.Parser.requirePrintEqualsInput(Parser.java:52)

The NonNull is from org.eclipse.jdt.annotations, but that should work for any type annotation which can be applied to arrays and types. When a normal array is used instead of the varargs, the parser doesn't produce an error.

Are you interested in contributing a fix to OpenRewrite?

probably not, I only feel confident in the recipes area, not the parser

Bananeweizen avatar Jan 03 '24 13:01 Bananeweizen

Thanks for reporting this issue here @Bananeweizen ; always good to see your detailed reports. Just yesterday @traceyyoshima merged some changes related to arrays and annotations in https://github.com/openrewrite/rewrite/pull/3860 ; Not sure if that also affects varargs, but it might be worth giving the snapshot versions a try. If not we can convert your sample into a unit test in rewrite-java-tck and verify that we're not making any unintended changes.

timtebeek avatar Jan 03 '24 13:01 timtebeek

I've reverted the PR and reopened this issue, as we will solve it in a slightly different way. I expect us to complete this next week.

knutwannheden avatar Jan 04 '24 14:01 knutwannheden