Skip to content

Conversation

@Jenson3210
Copy link
Contributor

@Jenson3210 Jenson3210 commented Feb 9, 2026

Summary

  • Fix NPE when using OR preconditions with nested ScanningRecipes
  • Add recursive registration and scanning of nested ScanningRecipes in DeclarativeRecipe
  • Add comprehensive tests for nested OR preconditions scenarios

Problem

When using the OR precondition pattern with ScanningRecipes like ModuleHasDependency or RepositoryContainsFile, the recipes fail with a NullPointerException:

java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicBoolean.get()" because "acc" is null
    at org.openrewrite.search.RepositoryContainsFile.getVisitor(RepositoryContainsFile.java:73)
    at org.openrewrite.config.DeclarativeRecipe.orVisitors(DeclarativeRecipe.java:483)

The root cause is that getInitialValue() only registers direct preconditions, but orVisitors() recursively looks up nested ScanningRecipes in precondition recipes' recipeLists that were never registered.

Solution

Added two helper methods that recursively traverse precondition recipes' recipeLists:

  1. registerNestedScanningRecipes() - Called from getInitialValue() to register all nested ScanningRecipes in the accumulator map
  2. scanNestedScanningRecipes() - Called from getScanner() to invoke the scanner on all nested ScanningRecipes

Test plan

Reproduces issue #6698 where OR preconditions with nested
ScanningRecipes fail with NPE because getInitialValue() only
registers direct preconditions, not nested ones.

Tests cover:
- Basic nested ScanningRecipe in OR precondition
- Precondition not met scenario
- Same scanning recipe with different parameters
- Deeply nested OR preconditions
- Multiple branches with same scanning recipe
Fixes #6698. When using OR preconditions with nested ScanningRecipes,
getInitialValue() and getScanner() now recursively traverse precondition
recipes' recipeLists to register and scan all nested ScanningRecipes.

This ensures orVisitors() can find accumulators for deeply nested
ScanningRecipes in the accumulator map.
@Jenson3210 Jenson3210 added the bug Something isn't working label Feb 9, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 9, 2026
@sambsnyd sambsnyd merged commit d634c65 into main Feb 9, 2026
2 checks passed
@sambsnyd sambsnyd deleted the fix-nested-scanning-preconditions branch February 9, 2026 21:05
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 9, 2026
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.

DeclarativeRecipe doesn't register accumulators for nested ScanningRecipes in OR preconditions

3 participants