8475: Writing events with fields not explicitly set can corrupt the recording #690
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.
Summary
Fixes an issue where events written with builtin type fields that are not explicitly set could cause field misalignment during JFR recording parsing, leading to corrupted field values.
Problem
When writing JFR events using the Writer API without explicitly setting values for builtin type fields (byte, char, short, int, long, float, double, boolean, string), the previous implementation in
Chunk.writeBuiltinType()would skip writing null builtin values (except for strings). This caused field alignment issues during parsing, where subsequent field values would be read at incorrect offsets.Solution
Modified
Chunk.writeBuiltinType()(lines 88-150) to write appropriate default values for null builtin types instead of skipping them:0falseAdditionally enhanced
TypedValueImpl.getDefaultImplicitFieldValue()to provideSystem.nanoTime()as default for@Timestampannotated fields in event types, ensuring valid monotonic timestamps.Testing
Added comprehensive test
ImplicitEventFieldsTest.eventWithAllBuiltinFieldsUnset()that:All 277 existing tests pass with the changes.
Files Changed
Chunk.java: Fixed builtin type serialization to write defaults instead of skippingTypedValueImpl.java: Enhanced default value handling for timestamp fieldsImplicitEventFieldsTest.java: Added comprehensive test for builtin defaultsType.java,TypedValueBuilder.java: Enhanced documentationFixes #8475
🤖 Generated with Claude Code
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jmc.git pull/690/head:pull/690$ git checkout pull/690Update a local copy of the PR:
$ git checkout pull/690$ git pull https://git.openjdk.org/jmc.git pull/690/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 690View PR using the GUI difftool:
$ git pr show -t 690Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jmc/pull/690.diff
Using Webrev
Link to Webrev Comment