Skip to content

Cannot rewrite S3Proxy AwsSdkAnonymousTest.java #6469

@gaul

Description

@gaul

Describe the bug

I am trying to rewrite S3Proxy's use of the V1 SDK with the V2 SDK. It fails with an error:

[ERROR] The recipe produced an error. Please report this to the recipe author.
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:6.19.0:dryRun (default-cli) on project s3proxy: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:6.19.0:dryRun failed: Error while visiting src/test/java/org/gaul/s3proxy/AwsSdkAnonymousTest.java: java.lang.ClassCastException: class org.openrewrite.java.tree.J$MethodInvocation cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$MethodInvocation and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @15e08615)

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Plugin should complete successfully.

Current Behavior

[ERROR] The recipe produced an error. Please report this to the recipe author.
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:6.19.0:dryRun (default-cli) on project s3proxy: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:6.19.0:dryRun failed: Error while visiting src/test/java/org/gaul/s3proxy/AwsSdkAnonymousTest.java: java.lang.ClassCastException: class org.openrewrite.java.tree.J$MethodInvocation cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$MethodInvocation and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @15e08615)
[ERROR]   software.amazon.awssdk.v2migration.S3PutObjectRequestToV2$Visitor.saveMetadataValueAndRemoveStatement(S3PutObjectRequestToV2.java:417)
[ERROR]   software.amazon.awssdk.v2migration.S3PutObjectRequestToV2$Visitor.visitMethodInvocation(S3PutObjectRequestToV2.java:96)
[ERROR]   software.amazon.awssdk.v2migration.S3PutObjectRequestToV2$Visitor.visitMethodInvocation(S3PutObjectRequestToV2.java:83)
[ERROR]   org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:4275)
[ERROR]   org.openrewrite.java.tree.J.accept(J.java:55)
[ERROR]   org.openrewrite.TreeVisitor.visit(TreeVisitor.java:242)
[ERROR]   org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:309)
[ERROR]   org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1310)
[ERROR]   org.openrewrite.java.JavaVisitor.lambda$visitContainer$34(JavaVisitor.java:1360)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:245)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:269)
[ERROR]   org.openrewrite.java.JavaVisitor.visitContainer(JavaVisitor.java:1360)
[ERROR]   org.openrewrite.java.JavaVisitor.visitMethodInvocation(JavaVisitor.java:877)
[ERROR]   software.amazon.awssdk.v2migration.S3PutObjectRequestToV2$Visitor.visitMethodInvocation(S3PutObjectRequestToV2.java:137)
[ERROR]   software.amazon.awssdk.v2migration.S3PutObjectRequestToV2$Visitor.visitMethodInvocation(S3PutObjectRequestToV2.java:83)
[ERROR]   org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:4275)
[ERROR]   ...

Reproduction Steps

$ git clone https://github.com/gaul/s3proxy.git
$ cd s3proxy
$ mvn org.openrewrite.maven:rewrite-maven-plugin:6.19.0:dryRun -Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:2.35.3 -Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.35.3

JDK version used

openjdk version "25" 2025-09-16

Operating System and version

Fedora release 42 (Adams)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.migration-toolThis issue is about the Java SDK v1 to v2 Migration Tool.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions