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

Trying to run open rewrite to migrate jmockit to mockito #503

Open
rajjaiswalsaumya opened this issue Apr 13, 2024 · 1 comment
Open

Trying to run open rewrite to migrate jmockit to mockito #503

rajjaiswalsaumya opened this issue Apr 13, 2024 · 1 comment
Labels
bug Something isn't working mockito question Further information is requested

Comments

@rajjaiswalsaumya
Copy link

rajjaiswalsaumya commented Apr 13, 2024

What version of OpenRewrite are you using?

I am using

  • Maven/Gradle plugin v5.28.0
  • rewrite-testing-frameworks v2.6.0

How are you running OpenRewrite?

I am using maven-plugin in multi-module project

<profiles>
		<profile>
			<id>openrewrite</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.openrewrite.maven</groupId>
						<artifactId>rewrite-maven-plugin</artifactId>
						<version>5.28.0</version>
						<configuration>
							<activeRecipes>
								<recipe>org.openrewrite.java.testing.jmockit.JMockitToMockito</recipe>
							</activeRecipes>
							<failOnDryRunResults>false</failOnDryRunResults>
						</configuration>
						<dependencies>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-testing-frameworks</artifactId>
								<version>2.6.0</version>
							</dependency>
						</dependencies>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

Is your project public? If so, can you share a link to it?
Nope, it is not public

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

Error:

java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
[ERROR]   java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
[ERROR]   java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
[ERROR]   java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
[ERROR]   java.base/java.util.Objects.checkIndex(Objects.java:372)
[ERROR]   java.base/java.util.ArrayList.get(ArrayList.java:459)
[ERROR]   org.openrewrite.java.testing.jmockit.ExpectationsBlockRewriter.removeExpectationsStatement(ExpectationsBlockRewriter.java:182)
[ERROR]   org.openrewrite.java.testing.jmockit.ExpectationsBlockRewriter.rewriteMethodBody(ExpectationsBlockRewriter.java:75)
[ERROR]   org.openrewrite.java.testing.jmockit.JMockitExpectationsToMockito$RewriteExpectationsVisitor.visitMethodDeclaration(JMockitExpectationsToMockito.java:72)
[ERROR]   org.openrewrite.java.testing.jmockit.JMockitExpectationsToMockito$RewriteExpectationsVisitor.visitMethodDeclaration(JMockitExpectationsToMockito.java:50)
[ERROR]   org.openrewrite.java.tree.J$MethodDeclaration.acceptJava(J.java:3672)
[ERROR]   org.openrewrite.java.tree.J.accept(J.java:59)
[ERROR]   org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
[ERROR]   org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
[ERROR]   org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1375)
[ERROR]   org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:401)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:176)

Also I see these errors after removing that class for which this was failing

Error while visiting ABCTest.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 @3790da63)
[ERROR]   org.openrewrite.java.testing.jmockit.SetupStatementsRewriter.isSetupStatement(SetupStatementsRewriter.java:98)
[ERROR]   org.openrewrite.java.testing.jmockit.SetupStatementsRewriter.rewriteMethodBody(SetupStatementsRewriter.java:59)
[ERROR]   org.openrewrite.java.testing.jmockit.JMockitExpectationsToMockito$RewriteExpectationsVisitor.visitMethodDeclaration(JMockitExpectationsToMockito.java:60)
[ERROR]   org.openrewrite.java.testing.jmockit.JMockitExpectationsToMockito$RewriteExpectationsVisitor.visitMethodDeclaration(JMockitExpectationsToMockito.java:50)
[ERROR]   org.openrewrite.java.tree.J$MethodDeclaration.acceptJava(J.java:3672)
[ERROR]   org.openrewrite.java.tree.J.accept(J.java:59)
[ERROR]   org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
[ERROR]   org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
[ERROR]   org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1375)
[ERROR]   org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:401)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
[ERROR]   org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:400)
[ERROR]   org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:88)
[ERROR]   org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:30)
[ERROR]   org.openrewrite.java.tree.J$Block.acceptJava(J.java:838)
[ERROR]   org.openrewrite.java.tree.J.accept(J.java:59)
@rajjaiswalsaumya rajjaiswalsaumya added the bug Something isn't working label Apr 13, 2024
@timtebeek
Copy link
Contributor

Thanks for the report @rajjaiswalsaumya ! That looks like an issue with that particular recipe implementation as it processes your test class. How much of your test class can you share to replicate this issue?

It would be great if we could minimize your setup to a unit test as seen in these two examples:
https://github.com/openrewrite/rewrite-testing-frameworks/tree/main/src/test/java/org/openrewrite/java/testing/jmockit

@timtebeek timtebeek added the question Further information is requested label Apr 15, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Apr 15, 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 mockito question Further information is requested
Projects
Status: Backlog
Development

No branches or pull requests

2 participants