Skip to content

Android: Add string EValue input support in JNI execute path#19526

Open
psiddh wants to merge 2 commits into
pytorch:mainfrom
psiddh:android-string-evalue-input
Open

Android: Add string EValue input support in JNI execute path#19526
psiddh wants to merge 2 commits into
pytorch:mainfrom
psiddh:android-string-evalue-input

Conversation

@psiddh
Copy link
Copy Markdown
Contributor

@psiddh psiddh commented May 12, 2026

The JNI execute_method handles Tensor, Int, Double, and Bool input types but was missing String support. Java EValue supports String (TYPE_CODE_STRING = 2) and the C++ output path already handles string EValues, but passing a string input would fail with "Unsupported input EValue type code".

String data and ArrayRef are heap-allocated via unique_ptr to ensure pointer stability as the vectors grow, since EValue stores a raw ArrayRef* that must remain valid through execution.

The JNI execute_method handles Tensor, Int, Double, and Bool input
types but was missing String support. Java EValue supports String
(TYPE_CODE_STRING = 2) and the C++ output path already handles
string EValues, but passing a string input would fail with
"Unsupported input EValue type code".

String data and ArrayRef are heap-allocated via unique_ptr to ensure
pointer stability as the vectors grow, since EValue stores a raw
ArrayRef<char>* that must remain valid through execution.

Co-authored-by: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 12, 2026 22:03
@psiddh psiddh requested a review from kirklandsign as a code owner May 12, 2026 22:03
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 12, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19526

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 5 New Failures, 3 Unrelated Failures

As of commit f19e1a2 with merge base fe98297 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 12, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for passing Java EValue strings through the Android JNI execute_method input conversion path, bringing input handling in line with the already-supported string output path.

Changes:

  • Adds JNI-side handling for JEValue::kTypeCodeString inputs by converting Java String to a native EValue string (ArrayRef<char>*).
  • Introduces heap-backed keepalive storage (unique_ptr) for string data and ArrayRef<char> objects to maintain pointer stability during execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/jni/jni_layer.cpp
Comment thread extension/android/jni/jni_layer.cpp
Address Copilot feedback:
- Check for null jstring from toStr() before dereferencing
- Add else branch that throws InvalidArgument for unrecognized
  EValue type codes instead of silently skipping them

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants