Skip to content

ChangeDependencyGroupIdAndArtifactId generates empty diffs on Java files after #7202 #7349

@timtebeek

Description

@timtebeek

What happened

The error: AssertionError: An empty diff was generated. The recipe incorrectly changed a reference without changing its contents.

Affected downstream repos

All started failing on April 11, 2026 (were green on April 10):

  • openrewrite/rewrite-hibernateMigrateToHibernate61Test.groupIdHibernateOrmRenamed()
  • openrewrite/rewrite-migrate-javaAddCommonAnnotationsDependenciesTest.changeAndUpgradeDependencyIfAnnotationJsr250Present()
  • moderneinc/rewrite-dropwizardMigrateDropwizardToSpringBoot3Test.addsSpringStarterJdbcWhenDropwizardDbIsUsed()

Root cause

ChangeDependencyGroupIdAndArtifactId.getVisitor() now processes Java files (line 350-351) and calls updateJavaSourceSet(), which modifies the JavaSourceSet marker via JavaSourceSet.updateOnSourceFile(). This returns a new SourceFile object (different identity), causing the recipe framework to generate a Result. However, the printed text is unchanged — only markers differ — so RewriteTest flags it as an "empty diff" error.

The PR's own test (updatesJavaSourceSetMarkerOnJavaFiles) handles this by providing explicit after text identical to before. But downstream tests don't know about this new behavior.

Suggested fix

Consider one of:

  1. Filter marker-only Results in InMemoryLargeSourceSet.getChangeset() — use Result.isLocalAndHasNoChanges() to skip Results where text is unchanged. This would need adjustment to the updatesJavaSourceSetMarkerOnJavaFiles test (use afterRecipe validation instead of after text matching).

  2. Relax the "empty diff" check in RewriteTest — instead of failing when a Result has no text change and no after spec, silently ignore the Result. This is a less invasive change but reduces bug detection coverage.

  3. Move marker updates out of the visitor phase — apply JavaSourceSet updates through a mechanism that doesn't generate Results (e.g., execution context sharing, or a post-processing step).

Workaround

Downstream repos can add explicit after text (identical to before) for Java source files in affected tests. PRs are being submitted for the affected repos.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions