Visitar URL original
Preserve JavaScript semantics in Java static-analysis recipes by jkschneider · Pull Request #1188 · openrewrite/rewrite-static-analysis · GitHub
Skip to content

Preserve JavaScript semantics in Java static-analysis recipes - #1188

Merged
jkschneider merged 5 commits into
mainfrom
fix/preserve-javascript-control-flow
Nov 3, 2026
Merged

jkschneider merged 5 commits into
mainfrom
fix/preserve-javascript-control-flow

Conversation

@jkschneider

@jkschneider jkschneider commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

CommonStaticAnalysis applies Java transformations that are unsafe for JavaScript/TypeScript. The wider repository runs exposed invalid switch templates and braces, lost boolean coercion and nullable fallbacks, public methods made protected, and removed bindings still captured by initializer closures.

Exclude JavaScript compilation units from MinimumSwitchCases, SimplifyBooleanReturn, SimplifyBooleanExpression, BooleanChecksNotInverted, InlineVariable, AbstractClassPublicConstructor and NeedBraces until their transformations support those semantics. Keep ordinary Java cleanup active, including files with search markers. Optional JavaScript detection uses the defining classloader, preventing a restricted thread context loader from permanently disabling the guard.

Observed examples include domain-locker (?.allow || false and a self-referencing backend closure), evs-explore (truthiness return), Ruff TSX (JavaTemplate error placeholders), tz-explorer (if (...) {call()}; else ...), and Spinnaker/systelab (public API methods becoming protected).

Validation: new synthetic JavaScript and isolated-loader cases fail before the corrections. Node probes reproduce SyntaxError, ReferenceError and boolean-value changes from the old output. Focused ordinary Java and language-guard tests pass. Java-only runtime probes pass with both optional language jars absent. The complete 273-repository composite rerun is being repeated with the latest guards; no JavaScript/Python RPC snapshot is required by the synthetic tests.

Combined source verification (2026-11-03): CommonStaticAnalysis over 273 repositories completed 264 modeled repositories, with 9 lacking LSTs and zero recipe errors; 103 repositories have results, covering 14,366 changed files. The available upstream suite passed 2,697 tests (16 skipped; 34 known unavailable Python/JavaScript RPC cases excluded), the commercial suite passed 160, and the affected core suites passed 102. This validation includes the combined follow-up recipe and core fixes.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Nov 3, 2026
@jkschneider jkschneider changed the title Preserve JavaScript switches and boolean-return coercion Preserve JavaScript control flow and member visibility Nov 3, 2026
@jkschneider jkschneider changed the title Preserve JavaScript control flow and member visibility Preserve JavaScript semantics in Java static-analysis recipes Nov 3, 2026
@jkschneider
jkschneider force-pushed the fix/preserve-javascript-control-flow branch from 64fef87 to 1677bf6 Compare November 3, 2026 22:50
@jkschneider
jkschneider enabled auto-merge (squash) November 3, 2026 22:50
@jkschneider
jkschneider merged commit 9e9a99b into main Nov 3, 2026
1 check passed
@jkschneider
jkschneider deleted the fix/preserve-javascript-control-flow branch November 3, 2026 22:53
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Nov 3, 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