Skip to content

Java: avoid provider resource extraction when library already exists in onnxruntime.native.path#27668

Merged
skottmckay merged 4 commits intomicrosoft:mainfrom
TsofnatMaman:fix/27655-skip-provider-extract-native-path
Mar 19, 2026
Merged

Java: avoid provider resource extraction when library already exists in onnxruntime.native.path#27668
skottmckay merged 4 commits intomicrosoft:mainfrom
TsofnatMaman:fix/27655-skip-provider-extract-native-path

Conversation

@TsofnatMaman
Copy link
Contributor

Summary

Fixes the Java native provider loading flow so that extractProviderLibrary checks
onnxruntime.native.path before attempting extraction from classpath resources.

Previously, when a provider library was already present in onnxruntime.native.path,
the Java loader could still attempt extractFromResources(...) first, and only fall
back to the configured native path afterwards. This caused an unnecessary extraction
attempt even though the library was already available on disk.

This change updates the lookup order to:

  1. Return immediately if the provider was already marked as ready
  2. Check whether the provider library already exists in onnxruntime.native.path
  3. Only if not found there, attempt extraction from classpath resources

Tests

Added a regression test covering the case where the requested provider library already
exists in onnxruntime.native.path.

The test verifies that:

  • extractProviderLibrary(...) returns true
  • extraction from resources is not attempted in that case

A small test-only hook was added to observe calls to extractFromResources(...) so the
regression can be validated directly and deterministically.

Issue

Fixes #27655

Copy link
Contributor

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

The core change is fine, but the hooks and other tricks to make a test are not ideal. It would be better to remove those hooks and the test, the logic is simple enough.

@TsofnatMaman TsofnatMaman requested a review from Craigacp March 16, 2026 09:02
Copy link
Contributor

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

LGTM

@skottmckay skottmckay enabled auto-merge (squash) March 17, 2026 01:40
@TsofnatMaman
Copy link
Contributor Author

Thanks for the review, @skottmckay
Some required checks are stuck in “Expected — Waiting for status to be reported”.
Could you please trigger them?
Thanks!

@skottmckay
Copy link
Contributor

/azp run Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Linux QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@skottmckay skottmckay merged commit c0fd2f7 into microsoft:main Mar 19, 2026
89 checks passed
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.

[Java] Redundant library extraction when onnxruntime.native.path is set

3 participants