Skip to content

Fix NPE with RepositoryHasDependency as precondition#174

Merged
timtebeek merged 2 commits intomainfrom
greg-fix-repo-has-dep-npe
Mar 24, 2026
Merged

Fix NPE with RepositoryHasDependency as precondition#174
timtebeek merged 2 commits intomainfrom
greg-fix-repo-has-dep-npe

Conversation

@greg-at-moderne
Copy link
Copy Markdown
Contributor

@greg-at-moderne greg-at-moderne commented Mar 24, 2026

What's changed?

Add a guard against NPE (NullPointerException) for when RepositoryHasDependency is used as a precondition.

What's your motivation?

Address NPEs observed in the Moderne product against some repositories:

java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicBoolean.get()" because "acc" is null
  org.openrewrite.java.dependencies.search.RepositoryHasDependency.getVisitor(RepositoryHasDependency.java:100)
  org.openrewrite.java.dependencies.search.RepositoryHasDependency.getVisitor(RepositoryHasDependency.java:28)
  org.openrewrite.config.DeclarativeRecipe.orVisitors(DeclarativeRecipe.java:517)
  org.openrewrite.config.DeclarativeRecipe.lambda$getRecipeList$1(DeclarativeRecipe.java:500)
  org.openrewrite.Preconditions.lambda$and$0(Preconditions.java:111)
  org.openrewrite.config.DeclarativeRecipe$PreconditionBellwether$1.<init>(DeclarativeRecipe.java:233)
  org.openrewrite.config.DeclarativeRecipe$PreconditionBellwether.getVisitor(DeclarativeRecipe.java:232)
  org.openrewrite.config.DeclarativeRecipe$BellwetherDecoratedRecipe.getVisitor(DeclarativeRecipe.java:284)
  org.openrewrite.config.DeclarativeRecipe$BellwetherDecoratedRecipe.getVisitor(DeclarativeRecipe.java:284)
  org.openrewrite.config.DeclarativeRecipe$BellwetherDecoratedRecipe.getVisitor(DeclarativeRecipe.java:284)
  org.openrewrite.scheduling.RecipeRunCycle.lambda$editSource$10(RecipeRunCycle.java:223)
  org.openrewrite.scheduling.RecipeStack.reduce(RecipeStack.java:60)
  org.openrewrite.scheduling.RecipeRunCycle.editSource(RecipeRunCycle.java:200)
  org.openrewrite.scheduling.RecipeRunCycle.lambda$editSources$8(RecipeRunCycle.java:194)
  io.moderne.worker.execution.CountingModerneLargeSourceSet.lambda$edit$4(CountingModerneLargeSourceSet.java:132)
  io.moderne.serialization.ModerneLargeSourceSet.edit(ModerneLargeSourceSet.java:450)
  ...

Considerations

I am not fully sure if this is enough. Maybe we should investigate the upstream, i.e. main OpenRewrite, whether it should be like this.

@greg-at-moderne greg-at-moderne self-assigned this Mar 24, 2026
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 24, 2026
@greg-at-moderne greg-at-moderne changed the title RepositoryHasDependency as precondition, acc == null Fix NPE with RepositoryHasDependency as precondition Mar 24, 2026
@greg-at-moderne greg-at-moderne marked this pull request as ready for review March 24, 2026 08:55
@timtebeek timtebeek merged commit 3e45634 into main Mar 24, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 24, 2026
@timtebeek timtebeek deleted the greg-fix-repo-has-dep-npe branch March 24, 2026 09:22
@sambsnyd
Copy link
Copy Markdown
Member

false is already the default value for AtomicBoolean, I don't see how this could make any difference at all.

@timtebeek
Copy link
Copy Markdown
Member

Restored in cd273ba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants