Skip to content

chore: make cached JNI static handles const#1251

Merged
mrousavy merged 2 commits into
mainfrom
codex/change-static-auto-to-const-in-codegen
Mar 6, 2026
Merged

chore: make cached JNI static handles const#1251
mrousavy merged 2 commits into
mainfrom
codex/change-static-auto-to-const-in-codegen

Conversation

@mrousavy
Copy link
Copy Markdown
Owner

@mrousavy mrousavy commented Mar 6, 2026

Motivation

  • Cached JNI method/field handles and generated constructor lookups were declared as mutable static auto, which is unnecessary and risks accidental mutation.
  • Making these cached handles static const auto improves correctness and allows the compiler to place them in read-only memory.

Description

  • Updated the Nitrogen codegen template in packages/nitrogen/src/syntax/kotlin/KotlinHybridObjectRegistration.ts to emit static const auto constructorFn for hybrid-object registration stubs.
  • Changed runtime JNI cached lookups from static auto to static const auto in packages/react-native-nitro-modules/android/src/main/cpp/core/JHybridObject.cpp and packages/react-native-nitro-modules/android/src/main/cpp/utils/JThreadUtils.hpp.
  • Updated generated Android on-load sources in the test packages packages/react-native-nitro-test/nitrogen/generated/android/NitroTestOnLoad.cpp and packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternalOnLoad.cpp to match the new codegen output.

Testing

  • Ran bun run build, which executes the project build and codegen for all packages, and the command completed successfully.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nitro-docs Skipped Skipped Mar 6, 2026 10:40am

Request Review

@mrousavy mrousavy merged commit 2b62b27 into main Mar 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants