Integrated: 8475: Writing events with fields not explicitly set can corrupt the recording
Jaroslav Bachorik
jbachorik at openjdk.org
Mon Feb 2 13:33:36 UTC 2026
On Wed, 3 Dec 2025 10:18:08 GMT, Jaroslav Bachorik <jbachorik at openjdk.org> wrote:
> ## 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:
> - Numeric types (byte, char, short, int, long, float, double): Write `0`
> - Boolean: Write `false`
> - String: Continue to write null encoding (existing behavior)
>
> Additionally enhanced `TypedValueImpl.getDefaultImplicitFieldValue()` to provide `System.nanoTime()` as default for `@Timestamp` annotated fields in event types, ensuring valid monotonic timestamps.
>
> ## Testing
> Added comprehensive test `ImplicitEventFieldsTest.eventWithAllBuiltinFieldsUnset()` that:
> - Creates an event with all 9 builtin type fields
> - Writes the event without setting any builtin field values
> - Includes a final field with an explicit value (99999L) to verify alignment
> - Verifies all default values are correct and the explicit field reads back correctly
>
> All 277 existing tests pass with the changes.
>
> ## Files Changed
> - `Chunk.java`: Fixed builtin type serialization to write defaults instead of skipping
> - `TypedValueImpl.java`: Enhanced default value handling for timestamp fields
> - `ImplicitEventFieldsTest.java`: Added comprehensive test for builtin defaults
> - `Type.java`, `TypedValueBuilder.java`: Enhanced documentation
>
> Fixes #8475
>
> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request has now been integrated.
Changeset: 020f06d7
Author: Jaroslav Bachorik <jbachorik at openjdk.org>
URL: https://git.openjdk.org/jmc/commit/020f06d717e32451b641b6b75e391410f0089b69
Stats: 430 lines in 5 files changed: 416 ins; 4 del; 10 mod
8475: Writing events with fields not explicitly set can corrupt the recording
Reviewed-by: hirt
-------------
PR: https://git.openjdk.org/jmc/pull/690
More information about the jmc-dev
mailing list