Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joda Recipe Varargs ArrayIndexOutOfBoundsException #642

Open
christopherfischer opened this issue Dec 20, 2024 · 2 comments
Open

Joda Recipe Varargs ArrayIndexOutOfBoundsException #642

christopherfischer opened this issue Dec 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@christopherfischer
Copy link

What version of OpenRewrite are you using?

I am using

  • Java 21
  • Maven CLI 3.9.6
  • rewrite-migrate-java-2.32.0-SNAPSHOT (1bcf355)

How are you running OpenRewrite?

I am using the Maven CLI , and my project is a multi module project.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:2.32.0-SNAPSHOT -Drewrite.activeRecipes=org.openrewrite.java.migrate.joda.JodaTimeRecipe -Drewrite.exportDatatables=true

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

org.openrewrite.internal.RecipeRunException: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 1
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:290)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1367)
	at org.openrewrite.java.JavaVisitor.lambda$visitContainer$35(JavaVisitor.java:1417)
	at org.openrewrite.java.JavaVisitor$$Lambda/0x000000080052dd10.apply(Unknown Source)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:243)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:265)
	at org.openrewrite.java.JavaVisitor.visitContainer(JavaVisitor.java:1417)
	at org.openrewrite.java.JavaVisitor.visitMethodInvocation(JavaVisitor.java:914)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:165)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:36)
	at org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:3927)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1367)
	at org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:397)
	at org.openrewrite.java.JavaVisitor$$Lambda/0x000000080052f5b8.apply(Unknown Source)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:243)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:265)
	at org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:396)
	at org.openrewrite.java.tree.J$Block.acceptJava(J.java:838)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.visitMethodDeclaration(JavaVisitor.java:875)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodDeclaration(JodaTimeVisitor.java:89)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodDeclaration(JodaTimeVisitor.java:36)
	at org.openrewrite.java.tree.J$MethodDeclaration.acceptJava(J.java:3673)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1367)
	at org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:397)
	at org.openrewrite.java.JavaVisitor$$Lambda/0x000000080052f5b8.apply(Unknown Source)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:243)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:265)
	at org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:396)
	at org.openrewrite.java.tree.J$Block.acceptJava(J.java:838)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.visitClassDeclaration(JavaVisitor.java:482)
	at org.openrewrite.java.tree.J$ClassDeclaration.acceptJava(J.java:1291)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
	at org.openrewrite.java.JavaVisitor.lambda$visitCompilationUnit$9(JavaVisitor.java:495)
	at org.openrewrite.java.JavaVisitor$$Lambda/0x000000080052e278.apply(Unknown Source)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:243)
	at org.openrewrite.internal.ListUtils.map(ListUtils.java:265)
	at org.openrewrite.java.JavaVisitor.visitCompilationUnit(JavaVisitor.java:495)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitCompilationUnit(JodaTimeVisitor.java:84)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitCompilationUnit(JodaTimeVisitor.java:36)
	at org.openrewrite.java.tree.J$CompilationUnit.acceptJava(J.java:1562)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:157)
	at org.openrewrite.ScanningRecipe$1.visit(ScanningRecipe.java:121)
	at org.openrewrite.ScanningRecipe$1.visit(ScanningRecipe.java:103)
	at org.openrewrite.scheduling.RecipeRunCycle.lambda$editSources$6(RecipeRunCycle.java:186)
	at org.openrewrite.scheduling.RecipeRunCycle$$Lambda/0x00000008005fef98.call(Unknown Source)
	at io.micrometer.core.instrument.AbstractTimer.recordCallable(AbstractTimer.java:178)
	at org.openrewrite.table.RecipeRunStats.recordEdit(RecipeRunStats.java:67)
	at org.openrewrite.scheduling.RecipeRunCycle.lambda$editSources$7(RecipeRunCycle.java:182)
	... 24 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 1
	at java.base/java.util.Arrays$ArrayList.get(Arrays.java:4266)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.migrateMethodCall(JodaTimeVisitor.java:234)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:176)
	at org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:36)
	at org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:3927)
	at org.openrewrite.java.tree.J.accept(J.java:59)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
	... 88 more

Are you interested in contributing a fix to OpenRewrite?

@christopherfischer christopherfischer added the bug Something isn't working label Dec 20, 2024
@christopherfischer
Copy link
Author

christopherfischer commented Dec 20, 2024

suitable test

@Test
    void varArgTest() {
        //language=java
        rewriteRun(
          java(
            """
            import org.joda.time.DateTime;

            class A {
                 void foo(DateTime dt) {
                    bar(dt, dt, dt, dt, DateTime.now());
                }

                void bar(DateTime... dts) {

                }
            }
            """,
            """
            import java.time.ZonedDateTime;

            class A {
                void foo(ZonedDateTime dt) {
                    bar(dt, dt, dt, dt, ZonedDateTime.now());
                }

                void bar(ZonedDateTime... dts) {

                }
            }
            """
          )
        );
    }

@timtebeek
Copy link
Contributor

Thanks for the reports and details @christopherfischer ! For a bit of context, these recipes are new and contributed by @amishra-u from our OSS community. Very helpful that you're providing a runnable test to make these easier to look into. I'll link the others here as well such that's there's one notification going out.

@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants