Skip to content

[Android] HermesSamplingProfiler JNI "disable" method incorrectly mapped to ::enable #56126

@elirangoshen

Description

@elirangoshen

Bug Description

In ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp, the registerNatives() function maps the JNI "disable" method to HermesSamplingProfiler::enable instead of
HermesSamplingProfiler::disable:

  void HermesSamplingProfiler::registerNatives() {
    javaClassLocal()->registerNatives({
        makeNativeMethod("enable", HermesSamplingProfiler::enable),
        makeNativeMethod("disable", HermesSamplingProfiler::enable),  // should be ::disable
        ...
    });
  }

This means calling HermesSamplingProfiler.disable() from Java actually calls enable() again, which can corrupt the sampling profiler state

The fix is a one-line change: HermesSamplingProfiler::enableHermesSamplingProfiler::disable.

  • I have run gradle clean and confirmed this bug does not occur with JSC

  • The issue is reproducible with the latest version of React Native.

    Hermes git revision: hermes-2025-07-07-RNv0.81.0-e0fc67142ec0763c6b6153ca2bf96df815539782
    React Native version: 0.81.4
    OS: Android
    Platform: arm64-v8a

Steps To Reproduce

This is a copy-paste bug visible by code inspection — no runtime reproduction steps needed.

Code example:

The bug is in ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp, line 37:

  void HermesSamplingProfiler::registerNatives() {
    javaClassLocal()->registerNatives({
        makeNativeMethod("enable", HermesSamplingProfiler::enable),
        makeNativeMethod("disable", HermesSamplingProfiler::enable),  // BUG: should be ::disable
        makeNativeMethod(
            "dumpSampledTraceToFile",
            HermesSamplingProfiler::dumpSampledTraceToFile),
    });
  }

The Expected Behavior

Calling HermesSamplingProfiler.disable() from Java should invoke HermesSamplingProfiler::disable() in C++, which calls hermesAPI->disableSamplingProfiler() and cleanly stops profiling. Instead, it calls
::enable() again, which corrupts the sampling thread state.

The fix is a one-character change: ::enable → ::disable on line 37.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds: Author FeedbackNeeds: ReproThis issue could be improved with a clear list of steps to reproduce the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions