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 NPE when invoked from child module in multi-module build, e.g.: spring-cloud-netflix-eureka-server #72

Closed
sambsnyd opened this issue Dec 11, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@sambsnyd
Copy link
Member

As part of this investigation openrewrite/rewrite-testing-frameworks#20, discovered using rewrite libs 6.1.5, maven plugin 2.4.1 on spring-cloud-netflix's "spring-cloud-netflix-eureka-server" module. The same thing would probably happen with any of the modules in the project.

The directory structure looks like this:

spring-cloud-netflix                   <- This folder contains the parent pom defining the modules
  | pom.xml                            <- The "relative" path to this pom comes out as an absolute path
  \ spring-cloud-netflix-eureka-server <- Maven is being invoked from this folder
       | pom.xml                       <- This is the pom where parsing produces the NPE

Stack trace:

java.lang.NullPointerException
    at org.openrewrite.maven.internal.MavenDownloader.lambda$download$3 (MavenDownloader.java:171)
    at java.util.Optional.map (Optional.java:265)
    at org.openrewrite.maven.internal.MavenDownloader.download (MavenDownloader.java:168)
    at org.openrewrite.maven.internal.RawMavenResolver.processParent (RawMavenResolver.java:327)
    at org.openrewrite.maven.internal.RawMavenResolver.processTask (RawMavenResolver.java:117)
    at org.openrewrite.maven.internal.RawMavenResolver.resolve (RawMavenResolver.java:101)
    at org.openrewrite.maven.internal.RawMavenResolver.resolve (RawMavenResolver.java:78)
    at org.openrewrite.maven.MavenParser.lambda$parseInputs$1 (MavenParser.java:71)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:195)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1654)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:913)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:578)
    at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:74)
    at org.openrewrite.Parser.parse (Parser.java:38)
    at org.openrewrite.maven.AbstractRewriteMojo.listChanges (AbstractRewriteMojo.java:155)
    at org.openrewrite.maven.RewriteWarnMojo.execute (RewriteWarnMojo.java:31)
    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:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    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)

This is the NPE-producing expression in question.

                            Path relativePomPath = Paths.get(pom.getSourcePath())
                                    .getParent() // "relativeTo" the directory containing this pom
                                    .resolve(Paths.get(relativePath, "pom.xml"))
                                    .normalize();

The relative path of the pom is just "pom.xml". Paths.get("pom.xml").getParent() returns null. null.resolve() therefore throws the NPE.

This situation appears to be the result of, or at least adjacent to, mismatched assumptions between the Maven Plugin and the Maven Parser.
Since maven is being invoked from with the spring-cloud-netflix/spring-cloud-netflix-eureka-server folder, that's the "root" folder for path relativization. But the logic in the parser seems to assume it would be invoked from spring-cloud-netflix.

And our plugin has to be invoked from within spring-cloud-netflix-eureka-server. Trying to run it from the root produces a message like this:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] spring-cloud-netflix-dependencies .................. SKIPPED
[INFO] Spring Cloud Netflix ............................... SKIPPED
[INFO] Spring Cloud Netflix Eureka Client ................. SKIPPED
[INFO] Spring Cloud Netflix Eureka Server ................. SKIPPED
[INFO] Spring Cloud Starter Netflix Eureka Client ......... SKIPPED
[INFO] Spring Cloud Starter Netflix Eureka Server ......... SKIPPED
[INFO] Spring Cloud Netflix Eureka Client TLS Tests ....... SKIPPED
[INFO] Spring Cloud Netflix Docs .......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.622 s
[INFO] Finished at: 2020-12-11T13:59:11-08:00
[INFO] Final Memory: 22M/97M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'rewrite' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/mnt/c/Users/Samuel.000/.m2/repository), spring-snapshots (https://repo.spring.io/libs-snapshot-local), spring-milestones (https://repo.spring.io/libs-milestone-local), spring-releases (https://repo.spring.io/release), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
@jkschneider jkschneider transferred this issue from openrewrite/rewrite Dec 12, 2020
sambsnyd added a commit to openrewrite/rewrite-gradle-plugin that referenced this issue Dec 14, 2020
@sambsnyd sambsnyd added the bug Something isn't working label Dec 15, 2020
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
None yet
Development

No branches or pull requests

1 participant