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

MavenParser fails on WindowsPath.relativize with 'other' has different root, when using multiple disks #546

Open
KaiqianYang opened this issue Mar 30, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@KaiqianYang
Copy link

I try to run recipes on the sample https://github.com/openrewrite/spring-petclinic-migration, but failed with:

Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run (default-cli) on project spring-petclinic: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run failed: 'other' has different root

My command was:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run "-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:LATEST" "-Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7"

Could you help me to run recipe on the sample project?

@knutwannheden
Copy link
Contributor

@KaiqianYang Thanks for reaching out to us. I'd like to make a few clarifications to make sure that I understand the problem correctly:

  1. Are you using the 2.1.x branch of https://github.com/openrewrite/spring-petclinic-migration?
  2. Which Java version are you using (for Maven the JAVA_HOME variable is used if set)?
  3. Just to be on the safe side, can you tell us exactly which version of the rewrite-maven-plugin and the rewrite-spring recipe gets used here?

Using the latest released versions of said artifacts I also get an error reported, but a different one:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run "-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:4.34.0" "-Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7"

If I however run the recipe using the command you provided, the run is actually successful.

@knutwannheden
Copy link
Contributor

@KaiqianYang I just learned that this is how LATEST behaves: When it finds a newer release in the local Maven repo (in my case 4.35.0-SNAPSHOT) it uses that instead.

I am however still unsure about the 'other' has different root error which you see getting reported. Can you run that with the --errors flag to see if there is a stacktrace? This appears to be a Windows problem involving drive letters and I would be interested to see where exactly this comes from.

@KaiqianYang
Copy link
Author

@KaiqianYang Thanks for reaching out to us. I'd like to make a few clarifications to make sure that I understand the problem correctly:

  1. Are you using the 2.1.x branch of https://github.com/openrewrite/spring-petclinic-migration?
  2. Which Java version are you using (for Maven the JAVA_HOME variable is used if set)?
  3. Just to be on the safe side, can you tell us exactly which version of the rewrite-maven-plugin and the rewrite-spring recipe gets used here?

Using the latest released versions of said artifacts I also get an error reported, but a different one:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run "-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:4.34.0" "-Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7"

If I however run the recipe using the command you provided, the run is actually successful.

@KaiqianYang I just learned that this is how LATEST behaves: When it finds a newer release in the local Maven repo (in my case 4.35.0-SNAPSHOT) it uses that instead.

I am however still unsure about the 'other' has different root error which you see getting reported. Can you run that with the --errors flag to see if there is a stacktrace? This appears to be a Windows problem involving drive letters and I would be interested to see where exactly this comes from.

@knutwannheden

  1. yes, i'm using the 2.1.x branch of https://github.com/openrewrite/spring-petclinic-migration
  2. I tried java 17.0.4.1 and java11, getting the same error
  3. [INFO] --- rewrite-maven-plugin:4.42.0:run (default-cli) @ spring-petclinic --- This log seems my run fetched rewrite-maven-plugin:4.42.0. As for rewrite-spring, I found this error happening on different recipes, getting the same error in mvn -U org.openrewrite.maven:rewrite-maven-plugin:run "-Drewrite.activeRecipes=org.openrewrite.yaml.format.Indents"

Error message:

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run (default-cli) on project spring-petclinic: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run failed: 'other' has different root -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run (default-cli) on project spring-petclinic: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run failed: 'other' has different root
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.42.0:run failed: 'other' has different root
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Oh your mentioning of Windows problem involving drive letters made me recall that I encountered this error before and after i change somewhere of the path name it recovered. This time my path is D:\itellijproject\spring-petclinic-migration.

Thanks.

@knutwannheden
Copy link
Contributor

@KaiqianYang As in the stack trace of this SO question I think that the root cause is an IllegalArgumentException getting thrown by sun.nio.fs.WindowsPath#relativize(): https://github.com/openjdk/jdk/blob/master/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java#L420

As I cannot reproduce the issue, can you maybe try running the build with mvnDebug instead of mvn and then connect with a debugger (Ctrl+Alt+F5 is your friend in IDEA) having a breakpoint set where this exception is raised (see above)? Seeing the stack trace of this original exception would really help us find the root cause of this.

@knutwannheden
Copy link
Contributor

@KaiqianYang Were you able to get any more details here?

@KaiqianYang
Copy link
Author

KaiqianYang commented Apr 12, 2023

@KaiqianYang Were you able to get any more details here?

@knutwannheden

Caused by: java.lang.IllegalArgumentException: 'other' has different root
    at sun.nio.fs.WindowsPath.relativize (WindowsPath.java:404)
    at sun.nio.fs.WindowsPath.relativize (WindowsPath.java:42)
    at org.openrewrite.Parser$Input.getRelativePath (Parser.java:190)
    at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:72)
    at org.openrewrite.Parser.parse (Parser.java:41)
    at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:363)
    at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:276)
    at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:54)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Sorry for the late reply, this is the stack trace.
(running with jdk 11)

And at this breakpoint, the child.root is C:\ while this.root being D:\. The child path is the location of my spring boot starter parent: C:\Users\kaiqianyang.FAREAST\.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.7.10\spring-boot-starter-parent-2.7.10.pom

        // can only relativize paths if root component matches
        if (!this.root.equalsIgnoreCase(child.root))
            throw new IllegalArgumentException("'other' has different root");

@azmau
Copy link

azmau commented Apr 19, 2023

I have a similar problem using the program from the "Running Rewrite without build tool plugins" documentation page against one of my projects. Again Java11, again Windows, again in the relativize method but with this stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: 'other' is different type of Path
	at java.base/sun.nio.fs.WindowsPath.relativize(WindowsPath.java:400)
	at java.base/sun.nio.fs.WindowsPath.relativize(WindowsPath.java:42)
	at org.openrewrite.Result$InMemoryDiffEntry.<init>(Result.java:260)
	at org.openrewrite.Result.computeDiff(Result.java:218)
	at org.openrewrite.Result.diff(Result.java:181)
	at org.openrewrite.Result.diff(Result.java:174)
	at org.openrewrite.Result.diff(Result.java:170)

In my case, this is D:\projects\head\article-mgmt (an ABSOLUTE path) and obj is src\main\java\articleMgmt\approval\ImportDelegate.java (a RELATIVE path).

Also, I'm using OpenRewrite 7.39.1.

@knutwannheden
Copy link
Contributor

@azmau @KaiqianYang Thank you both for the details. I hope this will be enough to reproduce abd fix the issue.

@rpau rpau transferred this issue from openrewrite/rewrite Apr 25, 2023
@timtebeek timtebeek added bug Something isn't working and removed question Further information is requested labels Apr 26, 2023
@timtebeek timtebeek moved this to Backlog in OpenRewrite Apr 26, 2023
@timtebeek timtebeek changed the title run failed: 'other' has different root when trying spring-petclinic-migration MavenParser fails on WindowsPath.relativize with 'other' has different root, when using multiple disks Dec 11, 2023
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

4 participants