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

Make Plugin.getGroupId() NonNull #4530

Merged

Conversation

rob-valor
Copy link
Contributor

@rob-valor rob-valor commented Sep 27, 2024

What's changed?

org.openrewrite.maven.tree.Plugin.getGroupId() is now non-null, defaulting to org.openrewrite.maven.tree.Plugin.PLUGIN_DEFAULT_GROUPID.

What's your motivation?

closes #4526

This ensures no more NullPointerExceptions can occur. Plugins can have a null groupId but not all places of the code take that situation into account. By automatically defaulting to org.apache.maven.plugins in the getter itself, there is no more need in the code to duplicate the nullability branching, and potentially forgetting it.

Anything in particular you'd like reviewers to focus on?

I was not able to provide a test for this case because the project being tested needs to use a parent pom that uses plugin management with plugins not explicitly setting <groupId>org.apache.maven.plugins</groupId>. I could not find a public pom file that I could use as a parent in the tests.

Locally there was 1, on first sight, non related test (MavenPomDownloaderTest.mirrorsOverrideRepositoriesInPom()) failing. I verified the changes by running our failing recipes again and now the NPE is gone.

Have you considered any alternatives or workarounds?

We bump into this issue because we use jgitver to manage out Maven versions. I tried to fix the issue in jgitver itself but it is using native maven to write the built pom file and it is in that native Maven code that the groupId for all plugins of org.apache.maven.plugins is not written to the new pom.xml file

@timtebeek timtebeek self-requested a review September 27, 2024 21:41
@timtebeek timtebeek added the bug Something isn't working label Sep 27, 2024
@timtebeek
Copy link
Contributor

Thanks for the suggestion @rob-valor ! I think this indeed more closely matches the default groupId handling in Maven. Let me tag @knutwannheden for a final check on serialization since I'm reviewing from mobile.

@DidierLoiseau
Copy link
Contributor

It’s strange that you would have to change org.openrewrite.maven.tree.Plugin because in #4507 I should have already ensured that Plugin.groupId is never null by initializing it with that same default value (see RawPom.java).

It’s true that the null check in RemoveRedundantDependencyVersions shouldn’t be needed anymore, but it shouldn’t cause a NPE.

Are you sure you are using the latest version of Rewrite? I have noticed with my own recipe library that sometimes the Maven Plugin does not pick the Rewrite version I want…

@rob-valor
Copy link
Contributor Author

rob-valor commented Sep 29, 2024

@DidierLoiseau, the issue is not in the (raw) pom of the project being rewritten. It's in the ResolvedPom when its parent pom has such defaults.

But since you mention the logic you added, maybe that should also just depend on the default getter logic I added. That way, it's possible to detect a missing groupId and I could add a recipe AddMissingPluginGroupId that adds the groupId explicitly for plugins that haven't set it. The getters should get a proper name in that case. Adding a getOriginalGroupId or renaming the one with the default logic to getGroupIdOrDefault (but that can cause NPE bugs again). @timtebeek @knutwannheden your thoughts on this?

@DidierLoiseau
Copy link
Contributor

@DidierLoiseau, the issue is not in the (raw) pom of the project being rewritten. It's in the ResolvedPom when its parent pom has such defaults.

I don’t understand what you mean by such defaults – the default value for groupId is indeed org.apache.maven.plugins (as per the maven xsd, and since #4507 it should be always filled in. I had even added an explicit test on RemoveRedundantDependencyVersions for the case of a parent (and child) not specifying the groupId. (BTW this is also an example of test with parent and child, so you don’t need to find a public pom for such tests)

But since you mention the logic you added, maybe that should also just depend on the default getter logic I added. That way, it's possible to detect a missing groupId and I could add a recipe AddMissingPluginGroupId that adds the groupId explicitly for plugins that haven't set it. The getters should get a proper name in that case. Adding a getOriginalGroupId or renaming the one with the default logic to getGroupIdOrDefault (but that can cause NPE bugs again). @timtebeek @knutwannheden your thoughts on this?

If you want to add the missing <groupId> everywhere, you’re going to traverse the XML anyway, right? So at that point, you can just check if the <plugin> tags have it, and add it when missing, you don’t need to check the corresponding Plugin object…

In fact, the AddOrUpdateChildTag recipe I proposed in #4533 could be used to do that. I just added a test case to show it – the only drawback is that it does not allow you to choose the position of the new <groupId> tag, so it would be the last element. You would need to apply OrderPomElements afterwards… but it seems ordering the GAV for plugins is missing, I think it’s an oversight.

@timtebeek
Copy link
Contributor

As a quick note in between holidays: there is already a recipe to make implicit groupIds explicit:
https://docs.openrewrite.org/recipes/maven/cleanup/explicitplugingroupid
It's also included with our Apache Maven best practices recipe:
https://docs.openrewrite.org/recipes/maven/bestpractices
Just to prevent any duplicate effort where existing recipes exist.

I am still chasing down a potentially related failure downstream in rewrite-jackson:
https://github.com/openrewrite/rewrite-jackson/actions/runs/11085613556/job/30802230458#step:5:1405

CodehausDependencyToFasterXMLTest > changeDependencies(String, String) > [1] pattern=2.12.x, expectedVersion=2.12.7 FAILED
    java.lang.AssertionError: Failed to parse sources or run recipe
        at org.openrewrite.test.RewriteTest.lambda$defaultExecutionContext$14(RewriteTest.java:631)
        at org.openrewrite.test.RewriteTest$$Lambda$513/0x00007fa1e8247618.accept(Unknown Source)
        at org.openrewrite.maven.MavenParser.parseInputs(MavenParser.java:100)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:280)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:130)
        at org.openrewrite.java.jackson.codehaus.CodehausDependencyToFasterXMLTest.changeDependencies(CodehausDependencyToFasterXMLTest.java:90)

        Caused by:
        java.io.UncheckedIOException: Failed to parse pom
            at app//org.openrewrite.maven.internal.RawPom.parse(RawPom.java:129)
            at app//org.openrewrite.maven.MavenParser.parseInputs(MavenParser.java:77)
            ... 3 more

            Caused by:
            com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property 'plugins' (of type `org.openrewrite.maven.internal.RawPom$Build`): Could not find creator property with name 'plugins' (known Creator properties: [plugin, pluginManagement])
             at [Source: (org.openrewrite.internal.EncodingDetectingInputStream); line: 1, column: 1]
                at app//com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:62)
                at app//com.fasterxml.jackson.databind.DeserializationContext.reportBadPropertyDefinition(DeserializationContext.java:1883)
                at app//com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:636)
                at app//com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:277)
                at app//com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:151)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:471)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:415)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:317)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
                at app//com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:659)
                at app//com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:552)
                at app//com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:60)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:347)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
                at app//com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
                at app//com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:669)
                at app//com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:5048)
                at app//com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4918)
                at app//com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3897)
                at app//org.openrewrite.maven.internal.RawPom.parse(RawPom.java:123)
                ... 4 more

Any quick insight there @DidierLoiseau ? You've been diving deeper there lately and have provided a lot of helpful context already.

@DidierLoiseau
Copy link
Contributor

As a quick note in between holidays: there is already a recipe to make implicit groupIds explicit:
https://docs.openrewrite.org/recipes/maven/cleanup/explicitplugingroupid

Didn’t know about that one. I have removed the example test from the other PR then.

Any quick insight there @DidierLoiseau ? You've been diving deeper there lately and have provided a lot of helpful context already.

Could it be that the @AllArgsConstructor is confusing Jackson because there are two constructors? (see this SO answer)
It’s strange that it works fine in Rewrite itself. It’s not very clear for me what changed between the builds however.

timtebeek added a commit that referenced this pull request Sep 30, 2024
As suggested on
- #4530 (comment)

To fix the downstream issues on rewrite-jackson
- #4530 (comment)
@timtebeek
Copy link
Contributor

Could it be that the @AllArgsConstructor is confusing Jackson because there are two constructors? (see this SO answer) It’s strange that it works fine in Rewrite itself. It’s not very clear for me what changed between the builds however.

Thanks a lot spotting that annotation and the linked context of the stackoverflow issue; I've pushed up a quick PR to remove it:

If that passes I'll see it through (assuming no harm) and see if that fixes rewrite-jackson.

timtebeek added a commit that referenced this pull request Sep 30, 2024
As suggested on
- #4530 (comment)

To fix the downstream issues on rewrite-jackson
- #4530 (comment)
@rob-valor
Copy link
Contributor Author

rob-valor commented Sep 30, 2024

@DidierLoiseau,

Are you sure you are using the latest version of Rewrite? I have noticed with my own recipe library that sometimes the Maven Plugin does not pick the Rewrite version I want…

Yes, I checked-out main branch of rewrite and rewrite-maven-plugin. In rewrite I added System.out.println() statements to find out which plugin was failing. I used that version of rewrite in my local version of rewrite-maven-plugin and ran the recipe with that version. Only then I found out that the NPE was caused by a plugin managed in our own company private version of Spring Boot parent. We have a project with a lot of auto-configuration and test libraries and Maven plugin configuration. It's for those plugins that we face the issue.

It’s strange that you would have to change org.openrewrite.maven.tree.Plugin because in #4507 I should have already ensured that Plugin.groupId is never null by initializing it with that same default value (see RawPom.java).

Well, I can only say, it is null in the place where I get the NPE, so there is some code path not covered.

Since org.openrewrite.maven.tree seems to be the API in rewrite-maven to work with Maven, it's not that strange to put the logic only there. That way, anywhere in the code, the default fallback logic is always used.

Insufficient test setup?

I used the entire pom of our project in an existing test org.openrewrite.maven.UpgradeParentVersionTest#upgradeToExactVersion because that's the recipe we run when it fails. I needed to add a <repositories> section to our company repository, and once that was done... that test passes. It seems that when I run the recipe in the project, there are other code paths because it still gives me a NPE. I also added the system out prints and it's clear that there are null groupids, but not in tests:

    private static @Nullable Plugin findPlugin(Xml.Tag tag, List<Plugin> plugins) {
        System.out.println("plugins");
        plugins.stream().forEach(p -> System.out.println(p.getGroupId() + ":"+p.getArtifactId()+ ":" + p.getVersion()));

Actual rewrite:

[INFO] Running recipe(s)...
plugins
org.apache.maven.plugins:maven-pmd-plugin:${maven-pmd-plugin.version}
...
null:maven-source-plugin:null
...
null:maven-enforcer-plugin:${maven-enforcer-plugin.version}
...

org.codehaus.mojo:versions-maven-plugin:${versions-maven-plugin.version}
org.codehaus.mojo:xml-maven-plugin:${xml-maven-plugin.version}
[ERROR] The recipe produced an error. Please report this to the recipe author.

Output during test:

org.apache.maven.plugins:maven-pmd-plugin:${maven-pmd-plugin.version}
...
org.apache.maven.plugins:maven-enforcer-plugin:${maven-enforcer-plugin.version}
...
org.apache.maven.plugins:maven-source-plugin:${maven-source-plugin.version}
...
org.codehaus.mojo:versions-maven-plugin:${versions-maven-plugin.version}
org.codehaus.mojo:xml-maven-plugin:${xml-maven-plugin.version}

@rob-valor
Copy link
Contributor Author

null origin

I added a new Exception("groupId is null. " + groupId + ":" + artifactId + ":" + version).printStackTrace(); in the constructor of Plugin when groupId is null. I hope this is of any use for those knowing the what, why and how of the Maven processing stuff 😉 This is the result:

java.lang.Exception: groupId is null. null:maven-source-plugin:null
        at org.openrewrite.maven.tree.Plugin.<init>(Plugin.java:49)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:126)
        at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:291)
        at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:301)
        at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:202)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:532)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1493)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:348)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:361)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:246)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
        at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:545)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:576)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:446)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1493)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:348)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:361)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:246)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
        at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:545)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:576)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:446)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1493)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:348)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
        at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3909)
        at org.openrewrite.maven.cache.RocksdbMavenPomCache.deserializePom(RocksdbMavenPomCache.java:190)
        at org.openrewrite.maven.cache.RocksdbMavenPomCache.getPom(RocksdbMavenPomCache.java:148)
        at org.openrewrite.maven.cache.CompositeMavenPomCache.getPom(CompositeMavenPomCache.java:76)
        at org.openrewrite.maven.internal.MavenPomDownloader.download(MavenPomDownloader.java:542)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPom(ResolvedPom.java:504)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:411)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:421)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:421)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:421)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentsRecursively(ResolvedPom.java:369)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolve(ResolvedPom.java:358)
        at org.openrewrite.maven.tree.ResolvedPom.resolve(ResolvedPom.java:176)
        at org.openrewrite.maven.tree.Pom.resolve(Pom.java:188)
        at org.openrewrite.maven.tree.Pom.resolve(Pom.java:171)
        at org.openrewrite.maven.MavenParser.parseInputs(MavenParser.java:113)
        at org.openrewrite.Parser.parse(Parser.java:59)
        at org.openrewrite.maven.MavenMojoProjectParser.parseMaven(MavenMojoProjectParser.java:552)
        at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles(MavenMojoProjectParser.java:145)
        at org.openrewrite.maven.AbstractRewriteBaseRunMojo.loadSourceSet(AbstractRewriteBaseRunMojo.java:236)
        at org.openrewrite.maven.AbstractRewriteBaseRunMojo.listResults(AbstractRewriteBaseRunMojo.java:152)
        at org.openrewrite.maven.AbstractRewriteRunMojo.execute(AbstractRewriteRunMojo.java:64)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
        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:298)
        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:960)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)

@rob-valor
Copy link
Contributor Author

rob-valor commented Sep 30, 2024

@DidierLoiseau,

Now that I looked into that caching thing there, I eventually found the issue. The RocksdbMavenPomCache had the serialized pom files with the missing groupId because of running rewrite-maven previously. So those cached serialized Poms were not handles by the new RawPom logic. Clearing the cache (~/.rewrite-cache) solved it.

Please to consider putting the logic of the groupId code only in the Plugin class. As you can see, the RawPom class is not the only place that creates instances of Plugin. But putting it only there, makes the rest of the codebase more resilient to assumptions that were made when putting it in RawPom 😉

If you want I can remove all duplicate logic and keep it only in the Plugin class. Since there's no need to know about the missing groupId in the Pluginclass because of the ExplicitPluginGroupId recipe, there won't be a need for additionally getting the potentially null groupId.

@DidierLoiseau
Copy link
Contributor

Now that I looked into that caching thing there, I eventually found the issue. The cache had the serialized pom files with the missing groupId because of running rewrite-maven previously. So those cached serialized Poms were not handles by the new RawPom logic. Clearing the cache (~/.rewrite-cache) solved it.

Good catch! This means we know what bug we are fighting against, and it would potentially be possible to write a unit test for that.

I’m not sure what’s best approach here though. This would only affect people who have run the old version of Rewrite and have such resolved poms in their cache already.

Maybe the best would be to validate the values in the Plugin constructor instead? One option is to use Lombok’s @Nonnull on the applicable fields. This would also cover other potential future bugs.

Also maybe there is a mechanism to clear the cache automatically when such a change is detected? (didn’t check)

@rob-valor
Copy link
Contributor Author

rob-valor commented Sep 30, 2024

Well, I think, if it's all covered in Plugin, so accepting null but returning org.apache.maven.plugins when it is, nobody is impacted. Also, any code in the codebase will always be null safe, regardless of what the future brings us (and the past left behind). And the missing groupIds in the cache are just fine.

There also won't be any such logic dangling around anymore (if I would clean it all up 😉 ). It's only in the upcoming Maven 4 that they fixed the groupId and will always include it when writing a pom.xml with Maven itself.

@timtebeek
Copy link
Contributor

Thanks for the detailed look here both! I'm hopping in and out, and will be away for the rest of the week before it's conference season starting next week. Let me know what the both of you settle on as the best way forward! 😅 I think handling a poisoned ~/.rewrite-cache might be best handled with an update to the docs for this one time change, as opposed to complicating handling.

@DidierLoiseau
Copy link
Contributor

Aha! Maybe I’ll meet you on Monday then @timtebeek 😉 Enjoy the rest of your holidays!

@sambsnyd sambsnyd merged commit 61f8091 into openrewrite:main Oct 4, 2024
2 checks passed
@sambsnyd
Copy link
Member

sambsnyd commented Oct 4, 2024

I think these changes look reasonable. Happy to continue to iterate as the discussion evolves. Thanks @rob-valor and @DidierLoiseau !

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
Archived in project
Development

Successfully merging this pull request may close these issues.

NullPointerException: Cannot invoke "String.equals(Object)" because "reqGroup" is null
4 participants