fix(java): repair JNI signatures out of sync with Java native declarations - #587
Open
hogan-yuan wants to merge 1 commit into
Open
fix(java): repair JNI signatures out of sync with Java native declarations#587hogan-yuan wants to merge 1 commit into
hogan-yuan wants to merge 1 commit into
Conversation
…larations Six JNI methods had a Rust extern "system" signature that no longer matched the Java native declaration, so every call aborted with "JNI call failed" (or read misaligned stack arguments): - getRankList / getShortTrades / getStrategy / shareholderDetail / valuationComparison: the Java side was migrated to an options object but the Rust JNI still read the old positional args. They now read the fields off the opts object via get_field. - getShortPositions: was missing the count parameter that the Rust core, Node.js and Python all require (the Rust JNI still expected it). Added count to the Java native decl and getShortPositions signature. Reported as longbridge/developers#1249 (getRankList).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in longbridge/developers#1249:
MarketContext.getRankListthrowsjava.lang.RuntimeException: JNI call failed.Root cause: the Java layer was migrated to an options-object API (
getRankList(RankListOptions),SdkNative.marketContextRankList(long, Object, callback)), but the Rustextern "system"JNI function was left in the old positional form(context, key: String, need_article: bool, callback). JNI marshals arguments according to the Java declaration, so the options object landed where aStringwas expected and the call aborted.Audit
I audited all 227
SdkNativenative declarations against their Rust JNI implementations (hand-written and macro-generated). The same regression class existed in six methods total:marketContextRankList(long, Object opts, cb)(key, need_article)key/needArticlefrom optsquoteContextShortTrades(long, Object opts, cb)(symbol, count)symbol/countfrom optsscreenerContextStrategy(long, Object opts, cb)(id: i64)idfrom optsfundamentalContextShareholderDetail(long, Object opts, cb)(symbol, object_id)symbol/objectIdfrom optsfundamentalContextValuationComparison(long, Object opts, cb)(symbol, currency, comparison_symbols)quoteContextShortPositions(long, String, cb)(symbol, count)count; added itThe first five: the Rust JNI now reads fields off the options object via
get_field(matching the siblingmarketContextTopMovers). No public API change.getShortPositionsis different: the Java binding had dropped thecountparameter that the Rust core, Node.js and Python bindings all expose (the Rust JNI still expected it, so the call crashed).getShortPositions(String symbol)→getShortPositions(String symbol, int count).The other 221 native methods matched exactly.
Verification
cargo build -p longbridge-javacleancargo clippy -p longbridge-java --all-features— no new warnings (6 pre-existing, all in untouched files)cargo +nightly fmt --all --checkcleanDocs fix (Java example for
getRankList) is in a separate longbridge/developers PR.