Skip to content

Fix NPE in JVMFlagAccess.setValue when getStringFlag returns null#11354

Open
matsumo-and wants to merge 1 commit into
DataDog:masterfrom
matsumo-and:fix/crashtracking-jvm-flag-null-check
Open

Fix NPE in JVMFlagAccess.setValue when getStringFlag returns null#11354
matsumo-and wants to merge 1 commit into
DataDog:masterfrom
matsumo-and:fix/crashtracking-jvm-flag-null-check

Conversation

@matsumo-and
Copy link
Copy Markdown

What Does This Do

Fixes a NullPointerException in JVMFlagAccess.setValue inside crash tracking initialization.
setValue calls getStringFlag after setStringFlag to verify the write succeeded, but
getStringFlag can return null on certain platforms where the JVM flag is not accessible via
the native ddprof API. The fix replaces .equals() with Objects.equals to handle null safely.

Motivation

On Apple Silicon (aarch64) and potentially other platforms, JVM flags like OnError and
OnOutOfMemoryError are not readable via JVMAccess.Flags.getStringFlag, which returns null.
This caused a NullPointerException logged as a WARN during crash tracking initialization on
every agent startup, polluting logs and causing noise in tests that assert no NPE appears.

Additional Notes

  • Only JVMFlagAccess (native path) is affected. JMXFlagAccess always returns true and is unaffected.
  • Returning false when getStringFlag returns null is semantically correct: it signals that
    the flag could not be verified as set, which is the expected behavior when the native API does
    not support the flag.

Contributor Checklist

On some platforms (e.g. Apple Silicon / aarch64), getStringFlag returns
null for flags like OnError and OnOutOfMemoryError because they are not
accessible via the native JVM flag API. Calling .equals() on the null
result causes a NullPointerException. Replace with Objects.equals to
handle null safely.

Signed-off-by: matsumo-and <yh134.toisanda@gmail.com>
@matsumo-and matsumo-and requested a review from a team as a code owner May 12, 2026 15:46
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.

1 participant