Keep Java Runtime.exec replacements out of non-Java sources - #990
Draft
martinfrancois wants to merge 1 commit into
Draft
Keep Java Runtime.exec replacements out of non-Java sources#990martinfrancois wants to merge 1 commit into
Runtime.exec replacements out of non-Java sources#990martinfrancois wants to merge 1 commit into
Conversation
4 tasks
martinfrancois
force-pushed
the
repro/runtime-exec-kotlin-guard
branch
from
August 15, 2026 21:20
4d47237 to
129ba8b
Compare
Runtime.exec replacements out of non-Java sources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggested review order: 10 of 52 (Score: 8)
Review first: #1006
What's changed?
Restricts
ReplaceDeprecatedRuntimeExecMethodsto Java compilation units by combining its Java 18 precondition withJavaFileChecker.The Kotlin regression test is now a passing no-change test. The complete
ReplaceDeprecatedRuntimeExecMethodsTestclass has 10 passing tests, including the existing Java transformations.What's your motivation?
Recipe:
org.openrewrite.staticanalysis.ReplaceDeprecatedRuntimeExecMethods.ReplaceDeprecatedRuntimeExecMethods.getVisitor()previously checked only for Java 18. That version marker also exists on Kotlin source, so theJavaIsoVisitorapplied a Java template to Kotlin.Before
Actual after the recipe
new String[] {...}is Java syntax and does not compile as Kotlin.Expected after the recipe
(unchanged)The recipe MUST NOT apply Java-only templates to non-Java compilation units.
I found this while preparing #976, which fixes a separate defect in the same recipe. Its description disclosed this Kotlin failure but does not fix it.
Confirmed real-world execution
MacCustomAppIcon.ktat516da0ac.org.openrewrite.recipe:rewrite-static-analysis:2.41.0.The project uses JDK 25. The released recipe changes its Kotlin
Runtime.exec(String)call to Javanew String[] {...}syntax, which is invalid Kotlin.Anything in particular you'd like reviewers to focus on?
Please review the positive
JavaFileCheckerguard. It keeps the existing Java 18 requirement and excludes Kotlin and other non-Java compilation units from the Java-specific implementation.Have you considered any alternatives or workarounds?
A Kotlin-specific implementation can use
arrayOf("ls", "-a"). That expands the recipe's supported languages and requires separate Kotlin transformation logic. This change instead preserves the recipe's existing Java behavior and prevents invalid output in other languages.Any additional context
Pre-existing tests changed: None.
ReplaceDeprecatedRuntimeExecMethodsTesttests passThis change was prepared with AI assistance. I reviewed the implementation, Kotlin output, tests, and contribution text.
Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv