Skip to content

Deduplicate file validation and UTF-8 checking utilities#17648

Merged
kirklandsign merged 3 commits intomainfrom
android/dedup-validation-utilities
Feb 24, 2026
Merged

Deduplicate file validation and UTF-8 checking utilities#17648
kirklandsign merged 3 commits intomainfrom
android/dedup-validation-utilities

Conversation

@kirklandsign
Copy link
Copy Markdown
Contributor

Summary

Java: Extract validateFilePath() into ExecuTorchRuntime and replace inline checks in Module, LlmModule, and TrainingModule. This also removes the "!!" typo in TrainingModule error messages.

C++: Move utf8_check_validity() from anonymous namespaces in jni_layer_llama.cpp and jni_layer_asr.cpp into the shared jni_helper.h/.cpp.

Test plan

CI

Java: Extract validateFilePath() into ExecuTorchRuntime and replace
inline checks in Module, LlmModule, and TrainingModule. This also
removes the "!!" typo in TrainingModule error messages.

C++: Move utf8_check_validity() from anonymous namespaces in
jni_layer_llama.cpp and jni_layer_asr.cpp into the shared
jni_helper.h/.cpp.
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 23, 2026

🔗 Helpful Links

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

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

❌ 3 New Failures, 35 Pending

As of commit 16a2501 with merge base c4e325d (image):

NEW FAILURES - The following jobs have failed:

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 Feb 23, 2026
@kirklandsign kirklandsign marked this pull request as ready for review February 23, 2026 23:34
Copilot AI review requested due to automatic review settings February 23, 2026 23:34
@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 deduplicates common validation utilities across the Android Java API surface and Android JNI C++ layer by centralizing file-path validation in ExecuTorchRuntime and UTF-8 validity checking in jni_helper.

Changes:

  • Java: Added ExecuTorchRuntime.validateFilePath() and replaced duplicated java.io.File readability checks in Module, LlmModule, and TrainingModule (also removing the “!!” typo in TrainingModule errors).
  • C++: Moved utf8_check_validity() from per-file anonymous namespaces into shared jni_helper.h/.cpp and updated JNI layers to reuse it.
  • JNI: Added jni_helper.h include where needed and imported the shared UTF-8 validator.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
extension/android/jni/jni_layer_llama.cpp Replaces local UTF-8 validator with shared jni_helper implementation.
extension/android/jni/jni_layer_asr.cpp Includes jni_helper.h and switches to shared UTF-8 validator.
extension/android/jni/jni_helper.h Declares shared utf8_check_validity() (adds required includes).
extension/android/jni/jni_helper.cpp Defines shared utf8_check_validity() implementation.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java Uses centralized file validation and removes duplicated checks/typo.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java Uses centralized file validation instead of inline File checks.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java Uses centralized file validation instead of inline File checks.
extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecuTorchRuntime.java Adds validateFilePath() utility for reuse across modules.

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

String moduleAbsolutePath, int loadMode, int numThreads);

private Module(String moduleAbsolutePath, int loadMode, int numThreads) {
ExecuTorchRuntime runtime = ExecuTorchRuntime.getRuntime();
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

ExecuTorchRuntime runtime = ExecuTorchRuntime.getRuntime(); is assigned but never used. Consider removing the local variable (and the call if it’s no longer needed) to avoid unused-variable warnings and reduce redundant initialization work.

Copilot uses AI. Check for mistakes.
…/executorch/extension/llm/LlmModule.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 24, 2026 19:26
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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.


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

@kirklandsign kirklandsign merged commit 466bef4 into main Feb 24, 2026
136 of 141 checks passed
@kirklandsign kirklandsign deleted the android/dedup-validation-utilities branch February 24, 2026 19:54
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