Skip to content

Conversation

@jbachorik
Copy link
Collaborator

@jbachorik jbachorik commented Dec 3, 2025

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


Progress

  • Commit message must refer to an issue
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

  • JMC-8475: Writing events with fields not explicitly set can corrupt the recording (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jmc.git pull/690/head:pull/690
$ git checkout pull/690

Update a local copy of the PR:
$ git checkout pull/690
$ git pull https://git.openjdk.org/jmc.git pull/690/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 690

View PR using the GUI difftool:
$ git pr show -t 690

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jmc/pull/690.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 3, 2025

👋 Welcome back jbachorik! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 3, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr label Dec 3, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 3, 2025

Webrevs

@jbachorik jbachorik marked this pull request as draft December 3, 2025 11:13
@openjdk openjdk bot removed the rfr label Dec 3, 2025
@jbachorik jbachorik marked this pull request as ready for review December 3, 2025 16:21
@openjdk openjdk bot added the rfr label Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant