Skip to content

Fix UpdateMockWebServerDispatcher classpath lookup#975

Merged
knutwannheden merged 1 commit intomainfrom
fix-mockwebserver-dispatcher-classpath
Apr 23, 2026
Merged

Fix UpdateMockWebServerDispatcher classpath lookup#975
knutwannheden merged 1 commit intomainfrom
fix-mockwebserver-dispatcher-classpath

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

@knutwannheden knutwannheden commented Apr 22, 2026

Motivation

.javaParser(JavaParser.fromJavaVersion().classpathFromResources(c, "mockwebserver-4.10", "okhttp-4.10"))

That artifact is only declared as a testParserClasspath dependency, so it lives in the test type table (src/test/resources/META-INF/rewrite/classpath.tsv.gz) and is not bundled with the published recipe artifact. Local unit tests pass because both type tables are on the classpath; production runs (Moderne CLI, etc.) blow up the moment they hit a Dispatcher.dispatch() override:

java.lang.IllegalArgumentException: Unable to find classpath resource dependencies beginning with: 'okhttp-4.10' in [..., mockwebserver-4.10.0, ...]
  org.openrewrite.java.JavaParser.dependenciesFromResources(JavaParser.java:171)
  org.openrewrite.java.JavaParser$Builder.classpathFromResources(JavaParser.java:318)
  org.openrewrite.java.testing.junit5.UpdateMockWebServerDispatcher$1$1.visitReturn(UpdateMockWebServerDispatcher.java:101)

Caught today across three rewrite-maven test files in openrewrite/rewrite (results).

Summary

  • Drop the unused "okhttp-4.10" argument from the classpathFromResources call. The template snippet only references MockResponse and .build() (a 5.x-only method, so the template parser is already tolerating unresolved members); no okhttp type is needed at template-parse time. Sibling recipe UpdateMockWebServerMockResponse uses just "mockwebserver3" for the same kind of template and works fine.

Test plan

  • Manually verified that UpdateMockWebServerMockResponseTest (which exercises the same Dispatcher.dispatch() rewrite path via dispatcherReturnTypeAndGetPathRename) still passes with only "mockwebserver-4.10" requested by the recipe.
  • Re-ran UpgradeOkHttpMockWebServerTest — green.
  • CI on this PR.

Reproduction

Run any recipe-execution path that exercises UpdateMockWebServerDispatcher against a project whose classpath has mockwebserver:4.10.x but does not bundle okhttp:4.10.x as a separately-named jar. The cleanest reproducer is the flagship run linked above; the affected files were:

  • rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java
  • rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeDependencyVersionTest.java
  • rewrite-maven/src/test/java/org/openrewrite/maven/internal/MavenPomDownloaderTest.java

The recipe asked for `okhttp-4.10` via `classpathFromResources`, but
that artifact is only bundled in the test type table — production runs
of the recipe (e.g. via the Moderne CLI) fail with
`IllegalArgumentException: Unable to find classpath resource
dependencies beginning with: 'okhttp-4.10'` whenever a project has
`mockwebserver` on its classpath.

The template snippet only references `MockResponse` and `.build()`
(itself a 5.x-only method, so the parser is already lenient about
unresolved members), so dropping the unused `okhttp-4.10` request is
sufficient and matches the sister `UpdateMockWebServerMockResponse`
recipe, which uses just `mockwebserver3`.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 22, 2026
@knutwannheden knutwannheden changed the title Fix UpdateMockWebServerDispatcher classpath lookup Fix UpdateMockWebServerDispatcher classpath lookup Apr 22, 2026
@knutwannheden knutwannheden merged commit 92de89a into main Apr 23, 2026
1 check passed
@knutwannheden knutwannheden deleted the fix-mockwebserver-dispatcher-classpath branch April 23, 2026 06:18
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant