Skip to content

Commit 6c8ae96

Browse files
Fix JNI exception class name casing, pin Rust toolchain, and remove deprecated surrealdb_unstable flag (#134)
1 parent 8a37a9d commit 6c8ae96

5 files changed

Lines changed: 74 additions & 27 deletions

File tree

.github/workflows/cross.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ jobs:
4040
- name: Install dependencies
4141
run: sudo apt-get update -y
4242

43+
- name: Read Rust toolchain version
44+
id: rust-version
45+
run: echo "CHANNEL=$(grep 'channel' rust-toolchain.toml | sed 's/.*"\(.*\)"/\1/')" >> $GITHUB_OUTPUT
46+
4347
- name: Set up Rust
4448
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
4549
with:
46-
toolchain: stable
50+
toolchain: ${{ steps.rust-version.outputs.CHANNEL }}
4751
targets: ${{ matrix.target }}
4852

4953
- name: Install cargo-ndk
5054
run: cargo install cargo-ndk
5155

5256
- name: Build
53-
env:
54-
RUSTFLAGS: '--cfg surrealdb_unstable'
5557
run: cargo ndk -t ${{ matrix.ndk }} build --release
5658

5759
- name: Upload so lib
@@ -91,15 +93,17 @@ jobs:
9193
sudo apt-get update
9294
sudo apt-get install -y ${{ matrix.apt-get }}
9395
96+
- name: Read Rust toolchain version
97+
id: rust-version
98+
run: echo "CHANNEL=$(grep 'channel' rust-toolchain.toml | sed 's/.*"\(.*\)"/\1/')" >> $GITHUB_OUTPUT
99+
94100
- name: Set up Rust
95101
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
96102
with:
97-
toolchain: stable
103+
toolchain: ${{ steps.rust-version.outputs.CHANNEL }}
98104
targets: ${{ matrix.target }}
99105

100106
- name: Build
101-
env:
102-
RUSTFLAGS: '--cfg surrealdb_unstable'
103107
run: |
104108
export ${{ matrix.linker }}
105109
cargo build --target ${{ matrix.target }} --release
@@ -122,15 +126,18 @@ jobs:
122126
- name: Cache Rust
123127
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2
124128

129+
- name: Read Rust toolchain version
130+
id: rust-version
131+
shell: bash
132+
run: echo "CHANNEL=$(grep 'channel' rust-toolchain.toml | sed 's/.*"\(.*\)"/\1/')" >> $GITHUB_OUTPUT
133+
125134
- name: Set up Rust
126135
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
127136
with:
128-
toolchain: stable
129-
target: ${{ matrix.arch }}-pc-windows-msvc
137+
toolchain: ${{ steps.rust-version.outputs.CHANNEL }}
138+
targets: ${{ matrix.arch }}-pc-windows-msvc
130139

131140
- name: Build
132-
env:
133-
RUSTFLAGS: '--cfg surrealdb_unstable'
134141
run: cargo build --target ${{ matrix.arch }}-pc-windows-msvc --release
135142

136143
- name: Upload artifact
@@ -155,14 +162,16 @@ jobs:
155162
- name: Cache Rust
156163
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2
157164

165+
- name: Read Rust toolchain version
166+
id: rust-version
167+
run: echo "CHANNEL=$(grep 'channel' rust-toolchain.toml | sed 's/.*"\(.*\)"/\1/')" >> $GITHUB_OUTPUT
168+
158169
- name: Set up Rust
159170
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
160171
with:
161-
toolchain: stable
172+
toolchain: ${{ steps.rust-version.outputs.CHANNEL }}
162173

163174
- name: Build
164-
env:
165-
RUSTFLAGS: '--cfg surrealdb_unstable'
166175
run: cargo build --target ${{ matrix.arch }}-apple-darwin --release
167176

168177
- name: Upload artifact

.github/workflows/reports.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
17+
1618
- name: Install dependencies
1719
run: sudo apt-get update
1820

1921
- name: Install Rust
2022
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
21-
with:
22-
toolchain: stable
23-
24-
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2523

2624
- name: Cache Rust
2725
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2
@@ -33,8 +31,6 @@ jobs:
3331
java-version: 25
3432

3533
- name: Build native lib
36-
env:
37-
RUSTFLAGS: '--cfg surrealdb_unstable'
3834
run: cargo build
3935

4036
- name: Setup Gradle

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14-
env:
15-
RUSTFLAGS: '--cfg surrealdb_unstable'
1614

1715
strategy:
1816
fail-fast: false
1917
matrix:
2018
java: [ '8', '11', '17', '21', '25' ]
2119

2220
steps:
21+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
22+
2323
- name: Install Rust
2424
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
25-
with:
26-
toolchain: stable
27-
components: clippy,rustfmt
28-
29-
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3025

3126
- name: Cache Rust
3227
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2

rust-toolchain.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This toolchain version should be aligned with the SurrealDB version
2+
# See: https://github.com/surrealdb/surrealdb/blob/v3.0.4/rust-toolchain.toml
3+
[toolchain]
4+
channel = "1.91"
5+
components = ["rustfmt", "clippy"]

src/main/rust/error.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) enum SurrealError {
1313
SurrealDBJni(String),
1414
}
1515

16-
const EXCEPTION: &str = "java/lang/exception";
16+
const EXCEPTION: &str = "java/lang/Exception";
1717
const NULL_POINTER_EXCEPTION: &str = "java/lang/NullPointerException";
1818
const NO_SUCH_ELEMENT_EXCEPTION: &str = "java/util/NoSuchElementException";
1919
const SURREAL_EXCEPTION: &str = "com/surrealdb/SurrealException";
@@ -307,3 +307,45 @@ impl From<surrealdb::Error> for SurrealError {
307307
SurrealError::SurrealDB(e)
308308
}
309309
}
310+
311+
#[cfg(test)]
312+
mod tests {
313+
use super::*;
314+
315+
/// Validates that JNI class name constants use correct Java casing.
316+
/// Java class names are case-sensitive in JNI; e.g. "java/lang/Exception"
317+
/// is valid but "java/lang/exception" would fail at runtime.
318+
#[test]
319+
fn jni_class_names_are_correctly_cased() {
320+
assert_eq!(EXCEPTION, "java/lang/Exception");
321+
assert_eq!(NULL_POINTER_EXCEPTION, "java/lang/NullPointerException");
322+
assert_eq!(
323+
NO_SUCH_ELEMENT_EXCEPTION,
324+
"java/util/NoSuchElementException"
325+
);
326+
assert_eq!(SURREAL_EXCEPTION, "com/surrealdb/SurrealException");
327+
assert_eq!(SERVER_EXCEPTION, "com/surrealdb/ServerException");
328+
}
329+
330+
/// Validates that each JNI class name segment that represents a class
331+
/// (the last segment) starts with an uppercase letter, following Java conventions.
332+
#[test]
333+
fn jni_class_names_have_uppercase_class_segment() {
334+
let constants = [
335+
EXCEPTION,
336+
NULL_POINTER_EXCEPTION,
337+
NO_SUCH_ELEMENT_EXCEPTION,
338+
SURREAL_EXCEPTION,
339+
SERVER_EXCEPTION,
340+
];
341+
for name in constants {
342+
let class_segment = name.rsplit('/').next().unwrap();
343+
assert!(
344+
class_segment.starts_with(char::is_uppercase),
345+
"JNI class name '{}' has a class segment '{}' that does not start with an uppercase letter",
346+
name,
347+
class_segment
348+
);
349+
}
350+
}
351+
}

0 commit comments

Comments
 (0)