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

NullPointerException: Cannot invoke "String.equals(Object)" because "reqGroup" is null #4526

Open
rob-valor opened this issue Sep 26, 2024 · 3 comments · May be fixed by #4530
Open

NullPointerException: Cannot invoke "String.equals(Object)" because "reqGroup" is null #4526

rob-valor opened this issue Sep 26, 2024 · 3 comments · May be fixed by #4530
Labels
bug Something isn't working

Comments

@rob-valor
Copy link

rob-valor commented Sep 26, 2024

What version of OpenRewrite are you using?

I am using

  • org.openrewrite:rewrite-maven 8.36.0
  • org.openrewrite.recipe:rewrite-spring 5.20.0

How are you running OpenRewrite?

command line

What is the smallest, simplest way to reproduce the problem?

don't have any atm.
We have a few projects that use several plugins that are not use by most projects. Those get the exception.
The issue is in not checking for null like in this place where null is checked.

I assume there are transitive plugins in plugin management using org.apache.maven.plugins plugins and not setting the groupId explicitly.

What did you expect to see?

no NullPointerException

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

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.41.0:run (default-cli) on project our-internal-project: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.41.0:run failed: Error while visiting pom.xml: java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "reqGroup" is null
[ERROR]   org.openrewrite.maven.MavenVisitor.findPlugin(MavenVisitor.java:407)
[ERROR]   org.openrewrite.maven.MavenVisitor.findManagedPlugin(MavenVisitor.java:400)
[ERROR]   org.openrewrite.maven.RemoveRedundantDependencyVersions$1.visitTag(RemoveRedundantDependencyVersions.java:201)
[ERROR]   org.openrewrite.maven.RemoveRedundantDependencyVersions$1.visitTag(RemoveRedundantDependencyVersions.java:163)
[ERROR]   org.openrewrite.xml.tree.Xml$Tag.acceptXml(Xml.java:454)
[ERROR]   org.openrewrite.xml.tree.Xml.accept(Xml.java:50)
[ERROR]   org.openrewrite.TreeVisitor.visit(TreeVisitor.java:245)
[ERROR]   org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:317)
[ERROR]   org.openrewrite.xml.XmlVisitor.lambda$visitTag$2(XmlVisitor.java:91)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
[ERROR]   org.openrewrite.xml.XmlVisitor.visitTag(XmlVisitor.java:91)
[ERROR]   org.openrewrite.maven.MavenIsoVisitor.visitTag(MavenIsoVisitor.java:38)
[ERROR]   org.openrewrite.maven.RemoveRedundantDependencyVersions$1.visitTag(RemoveRedundantDependencyVersions.java:219)
[ERROR]   org.openrewrite.maven.RemoveRedundantDependencyVersions$1.visitTag(RemoveRedundantDependencyVersions.java:163)
[ERROR]   org.openrewrite.xml.tree.Xml$Tag.acceptXml(Xml.java:454)
[ERROR]   org.openrewrite.xml.tree.Xml.accept(Xml.java:50)

Are you interested in contributing a fix to OpenRewrite?

I could, but the fix seems so small that a regular contributor or team member can also fix it quickly.

@rob-valor rob-valor added the bug Something isn't working label Sep 26, 2024
@rob-valor
Copy link
Author

I just found out that the missing groupId issue must be on our side. Several plugins are inherited by a parent pom. In the pom that is pulled by Maven, there is no more <groupId>org.apache.maven.plugins</groupId> to be found but in the sources of that parent pom, the groupId is explicitly set.

Although I'll probably can fix the issue in the build of our parent project, for Maven, it still is valid to not have any groupId set.

@rob-valor
Copy link
Author

rob-valor commented Sep 27, 2024

We're using jgitver and that's the one that's throwing away the <groupId>org.apache.maven.plugins</groupId> because of a native Maven thing. In MavenXpp3Writer the groupId is not written when it's the default.

1371        if ( ( plugin.getGroupId() != null ) && !plugin.getGroupId().equals( "org.apache.maven.plugins" ) )
1372        {
1373            serializer.startTag( NAMESPACE, "groupId" ).text( plugin.getGroupId() ).endTag( NAMESPACE, "groupId" );
1374        }

That behavior can also be found when generating an effective pom. Only starting from upcoming version 4 of Maven, the groupId is included, even when it is null (output will be the default org.apache.maven.plugins)

I've fixed the missing groupIds from parent plugins by building without jgitver, for both the currently used and the newly to use parent pom. That fixes the issue. But... since the project itself can use plugin(management) with missing groupId (found several tests for that), I would expect that higher up the pom hierarchy that's also possible and supported.

@rob-valor rob-valor linked a pull request Sep 27, 2024 that will close this issue
@rob-valor
Copy link
Author

rob-valor commented Sep 30, 2024

Temporary (?) fix

For those landing here because of the same issue: for the time being, you can delete your /.rewrite-cache folder. Changes made to rewrite-maven which should prevent null groupIds are not taking into account that there can be plugins in that cache that are serialized without a groupId.

For more details, check the comments on the PR.

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: No status
Development

Successfully merging a pull request may close this issue.

1 participant