Skip to content

FIX @W-24886726@ [BUG][code-analyzer] Java auto-detection parses java -version on 'exit' and reads truncated stderr: JAVA_TOOL_OPTIONS notice yields "Java v8.0.0" - #521

Open
nikhil-mittal-165 wants to merge 3 commits into
devfrom
fix/issue-2110-java-version-close-event
Open

nikhil-mittal-165 wants to merge 3 commits into
devfrom
fix/issue-2110-java-version-close-event

Conversation

@nikhil-mittal-165

Copy link
Copy Markdown
Contributor

Summary

Addresses code-analyzer issue 2110.

Root Cause

RuntimeJavaVersionIdentifier.identifyJavaVersion in code-analyzer-pmd-engine/src/JavaVersionIdentifier.ts parses collected stderr in the child process exit handler. Node documents that stdio streams may still be open at exit, so stderr can be incomplete. When JAVA_TOOL_OPTIONS is set, the JVM prints a Picked up JAVA_TOOL_OPTIONS: ... line first. If only that chunk has arrived, the version regex does not match and the semver.coerce fallback takes the first number from the notice (8 from -Dfile.encoding=UTF-8), producing Java v8.0.0. The result is also cached. The close event fires after the streams are drained; JavaCommandExecutor in code-analyzer-engine-api already uses it.

Fix

Use the child process close event instead of exit so stderr is fully drained before parsing the java version. Added a regression test for a late-arriving version line after the JAVA_TOOL_OPTIONS notice. The 81 other pmd-engine test failures also occur on origin/dev.

Testing

  • Unit test added for the late-arriving version line
  • npx jest test/JavaVersionIdentifier.test.ts: 8 passed, 8 total

Functional Testing Evidence

  • Test 1: fake-java repro (JAVA_TOOL_OPTIONS notice then delayed openjdk 25.0.5 line) - fixed build via close returns 25.0.5, exit-patched copy returns 8.0.0, close stderr contains openjdk version 25.0.5 - PASS
  • Test 2: npx jest test/JavaVersionIdentifier.test.ts - 8 passed, 8 total - PASS

Overall Status: PASS ✅

Files Changed

  • packages/code-analyzer-pmd-engine/src/JavaVersionIdentifier.ts
  • packages/code-analyzer-pmd-engine/test/JavaVersionIdentifier.test.ts

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@git2gus

git2gus Bot commented Nov 12, 2026

Copy link
Copy Markdown

Git2Gus App is installed but the .git2gus/config.json doesn't have right values. You should add the required configuration.

@nikhil-mittal-165 nikhil-mittal-165 changed the title fix: [BUG][code-analyzer] Java auto-detection parses java -version on 'exit' and reads truncated stderr: JAVA_TOOL_OPTIONS notice yields "Java v8.0.0" FIX @W-24886726@ [BUG][code-analyzer] Java auto-detection parses java -version on 'exit' and reads truncated stderr: JAVA_TOOL_OPTIONS notice yields "Java v8.0.0" Nov 12, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nikhil-mittal-165
nikhil-mittal-165 marked this pull request as ready for review November 12, 2026 12:40
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants