Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a86109e

Browse files
committed
fix(java): box OAuth native pointer as java.lang.Long; add slf4j-nop; fix Main.java import
- Add JavaLong newtype (IntoJValue boxes i64 as java.lang.Long object) to fix WrongJValueType("object", "long") panic in async_util::execute - Use JavaLong in oauthBuild return value so callback receives a proper object - Remove stray java.io.ObjectInputFilter.Config import from test/Main.java - Add slf4j-nop-1.7.30.jar to libs/ and all three classpaths in Makefile.toml to silence SLF4J StaticLoggerBinder warning at runtime
1 parent 0f81868 commit a86109e

15 files changed

Lines changed: 63 additions & 26 deletions

java/Makefile.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ args = [
99
"-h",
1010
"c",
1111
"-cp",
12-
"libs/native-lib-loader-2.4.0.jar;libs/slf4j-api-1.7.30.jar;libs/gson-2.10.1.jar",
12+
"libs/native-lib-loader-2.4.0.jar;libs/slf4j-api-1.7.30.jar;libs/slf4j-nop-1.7.30.jar;libs/gson-2.10.1.jar",
1313
"-sourcepath",
1414
"javasrc/src/main/java",
1515
"-d",
@@ -22,7 +22,7 @@ cwd = "java"
2222
[tasks.compile-java-test]
2323
args = [
2424
"-cp",
25-
"libs/native-lib-loader-2.4.0.jar;libs/slf4j-api-1.7.30.jar;libs/gson-2.10.1.jar",
25+
"libs/native-lib-loader-2.4.0.jar;libs/slf4j-api-1.7.30.jar;libs/slf4j-nop-1.7.30.jar;libs/gson-2.10.1.jar",
2626
"-sourcepath",
2727
"javasrc/src/main/java",
2828
"-d",
@@ -162,7 +162,7 @@ command = "java"
162162
args = [
163163
"-Djava.library.path=target/debug",
164164
"-cp",
165-
"java/classes;java/libs/native-lib-loader-2.4.0.jar;java/libs/slf4j-api-1.7.30.jar;java/libs/gson-2.10.1.jar",
165+
"java/classes;java/libs/native-lib-loader-2.4.0.jar;java/libs/slf4j-api-1.7.30.jar;java/libs/slf4j-nop-1.7.30.jar;java/libs/gson-2.10.1.jar",
166166
"Main",
167167
]
168168
dependencies = ["java", "compile-java-test"]

java/libs/slf4j-nop-1.7.30.jar

3.93 KB
Binary file not shown.

java/src/oauth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use jni::{
55
};
66
use longport::oauth::{OAuth, OAuthBuilder};
77

8-
use crate::{async_util, error::jni_result};
8+
use crate::{async_util, error::jni_result, types::JavaLong};
99

1010
// ── OAuth native handle
1111
// ───────────────────────────────────────────────────────
@@ -51,7 +51,7 @@ pub unsafe extern "system" fn Java_com_longport_SdkNative_oauthBuild(
5151
})
5252
.await
5353
.map_err(|e| crate::error::JniError::Other(e.to_string()))?;
54-
Ok(Box::into_raw(Box::new(oauth)) as jlong)
54+
Ok(JavaLong::from(Box::into_raw(Box::new(oauth)) as jlong))
5555
})?;
5656
Ok(())
5757
})

java/src/types/classes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ impl_java_class!(
132132
impl_java_class!(
133133
"com/longport/quote/PrePostQuote",
134134
longport::quote::PrePostQuote,
135-
[
136-
last_done, timestamp, volume, turnover, high, low, prev_close
137-
]
135+
[last_done, timestamp, volume, turnover, high, low, prev_close]
138136
);
139137

140138
impl_java_class!(

java/src/types/datetime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use std::borrow::Cow;
22

33
use jni::{
4-
JNIEnv,
54
errors::Result,
65
objects::{JValue, JValueOwned},
6+
JNIEnv,
77
};
88
use time::{Date, Month, OffsetDateTime, PrimitiveDateTime, Time};
99

1010
use crate::{
1111
init::{
12-
TIME_INSTANT_CLASS, TIME_LOCALDATE_CLASS, TIME_LOCALDATETIME_CLASS, TIME_LOCALTIME_CLASS,
12+
TIME_INSTANT_CLASS, TIME_LOCALDATETIME_CLASS, TIME_LOCALDATE_CLASS, TIME_LOCALTIME_CLASS,
1313
TIME_OFFSETDATETIME_CLASS, TIME_ZONE_ID,
1414
},
15-
types::{ClassLoader, FromJValue, IntoJValue, JSignature, get_field},
15+
types::{get_field, ClassLoader, FromJValue, IntoJValue, JSignature},
1616
};
1717

1818
impl ClassLoader for OffsetDateTime {

java/src/types/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::borrow::Cow;
22

3-
use jni::{JNIEnv, errors::Result, objects::JValueOwned};
3+
use jni::{errors::Result, objects::JValueOwned, JNIEnv};
44
use longport::Decimal;
55

66
use crate::{

java/src/types/enum_types.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::borrow::Cow;
22

33
use jni::{
4-
JNIEnv,
54
errors::Result,
65
objects::{JObject, JValueOwned},
6+
JNIEnv,
77
};
88
use longport_java_macros::impl_java_enum;
99

@@ -348,9 +348,7 @@ impl_java_enum!(
348348
impl_java_enum!(
349349
"com/longport/trade/OrderType",
350350
longport::trade::OrderType,
351-
[
352-
Unknown, LO, ELO, MO, AO, ALO, ODD, LIT, MIT, TSLPAMT, TSLPPCT, TSMAMT, TSMPCT, SLO
353-
]
351+
[Unknown, LO, ELO, MO, AO, ALO, ODD, LIT, MIT, TSLPAMT, TSLPPCT, TSMAMT, TSMPCT, SLO]
354352
);
355353

356354
impl_java_enum!(

java/src/types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ mod sub_flags;
1212
use std::borrow::Cow;
1313

1414
use jni::{
15-
JNIEnv,
1615
errors::Result,
1716
objects::{GlobalRef, JObject, JValueOwned},
1817
strings::JNIString,
18+
JNIEnv,
1919
};
2020

2121
pub(crate) use self::{
@@ -25,7 +25,7 @@ pub(crate) use self::{
2525
},
2626
object_array::ObjectArray,
2727
primary_array::PrimaryArray,
28-
primary_types::JavaInteger,
28+
primary_types::{JavaInteger, JavaLong},
2929
};
3030

3131
pub(crate) trait ClassLoader {

java/src/types/object_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::borrow::Cow;
22

33
use jni::{
4-
JNIEnv,
54
errors::Result,
65
objects::{JObject, JObjectArray, JValueOwned},
6+
JNIEnv,
77
};
88

99
use crate::types::{ClassLoader, FromJValue, IntoJValue, JSignature};

java/src/types/optional.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::borrow::Cow;
22

33
use jni::{
4-
JNIEnv,
54
errors::Result,
65
objects::{JObject, JValueOwned},
6+
JNIEnv,
77
};
88

99
use crate::types::{ClassLoader, FromJValue, IntoJValue, JSignature};

0 commit comments

Comments
 (0)