Repository navigation
fix: extend J9 VM detection to cover IBM JDK 8 (issue #7956) - #7961
Open
divine-punishment wants to merge 1 commit into
Open
divine-punishment wants to merge 1 commit into
divine-punishment wants to merge 1 commit into
Conversation
IBM JDK 8 reports java.vm.name as "IBM J9 VM", which was not matched by
the previous contains("OpenJ9") check. As a result all J9-specific guards
were skipped on IBM JDK 8: the Unsafe string paths were selected and
STRING_CREATOR_JDK8 (built from the HotSpot-internal String(char[], boolean)
constructor) was used to build date strings in DateUtils, producing strings
with trailing '\u0000' (issue alibaba#7956).
- Match "J9" in java.vm.name so both "IBM J9 VM" and "Eclipse OpenJ9 VM"
are detected
- Gate STRING_CREATOR_JDK8 initialization on !openj9 so IBM JDK 8 falls
back to the standard new String(char[]) path
No behavioral change on HotSpot; all detection happens at class-init time
outside hot paths.
This branch has not been deployed
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.
What this PR does / why we need it?
Fixes #7956.
On IBM JDK 8 (
java.vm.nameis"IBM J9 VM"),JSON.toJSONStringproduced date strings with trailing\u0000.Root cause:
JDKUtilsdetects J9-based VMs withjvmName.contains("OpenJ9"), which only matches Eclipse OpenJ9. Classic IBM JDK 8 reports"IBM J9 VM", so all J9-specific guards were skipped:STRING_CREATOR_JDK8(built from the HotSpot-internal package-privateString(char[], boolean)constructor) was used byDateUtilsto build date strings, andJSONWriterUTF16JDK8UF(Unsafe access toString.value) was selected as the writer. These HotSpot internals behave differently on J9-based VMs, yielding strings with trailing\0— which is why only date fields were affected.Summary of your change
JDKUtils.java: match"J9"injava.vm.nameso both"IBM J9 VM"and"Eclipse OpenJ9 VM"are detectedJDKUtils.java: gateSTRING_CREATOR_JDK8initialization on!openj9, so IBM JDK 8 falls back to the standardnew String(char[])pathIssue7956Testcovering all built-in date formats and theJSON.toJSONString(map, format)scenario from the issueNo behavioral change on HotSpot — all detection happens at class-init time, outside hot paths. On IBM JDK 8 the Unsafe shortcuts are replaced by the standard constructor (slightly slower, but correct), consistent with the existing Eclipse OpenJ9 handling strategy.
Please indicate you've done the following:
中文说明
修复内容
Fixes #7956:IBM JDK 8 上
JSON.toJSONString序列化日期时结果末尾多出\u0000。根因:
JDKUtils用jvmName.contains("OpenJ9")检测 J9 虚拟机,只能命中 Eclipse OpenJ9;经典 IBM JDK 8 的java.vm.name是"IBM J9 VM",导致所有 J9 防护失效:STRING_CREATOR_JDK8(基于 HotSpot 内部包私有构造器String(char[], boolean))被DateUtils用于构造日期字符串,Writer 也选中了 Unsafe 路径的JSONWriterUTF16JDK8UF。J9 系虚拟机对这些 HotSpot 内部机制的实现语义不同,导致构造出的字符串带尾部\0,这也解释了为什么只有日期字段受影响。修改方式
java.vm.name匹配"J9",同时覆盖"IBM J9 VM"与"Eclipse OpenJ9 VM"STRING_CREATOR_JDK8初始化加!openj9门槛,IBM JDK 8 回退到标准new String(char[])路径Issue7956Test,覆盖全部内建日期格式及 issue 中的JSON.toJSONString(map, format)场景对 HotSpot 用户零影响——检测全部发生在类初始化阶段,不在热路径上;与项目对 Eclipse OpenJ9 的既有处理策略一致。
验证
./mvnw validate— Checkstyle 0 违规./mvnw -pl core clean test— 2170 个测试类 / 8350 个用例全部通过./mvnw -pl core clean test -Dfastjson2.creator=reflect— 通过