Skip to content

throw execptions from java #75

@milyin

Description

@milyin

The zenoh-jni-runtime in the common-jni branch (use it as destination) throws exceptions from the Rust code.
This is inconvenient for zenoh-kotlin library (in the different repo) which reuses zenoh-jni-runtime and have to wrap each jni call to runCatching.
The new JNI API functions will follow this pattern:

  • their return value should include error variant:
    • negative value for enum ints
    • null for objects/strings
    • integer with negative value instead of bool
    • etc...
  • they accept string parameter error. In case of error they return error variant value and set error string to error message. In case of success error stays intact

No exception throwing from zenoh-jni-runtime anymore.
No export of error type from zenoh-jni-runtime.

Error type export and throwing exception is performed on zenoh-java level

---PARAMETERS---
stack: [{"pipeline":"plan","calling_stage":"call_work"},{"pipeline":"plan","calling_stage":"working"}]
work_branch: zbobr_fix-75-throw-execptions-from-java
destination_branch: common-jni
pr_url: milyin-zenoh-zbobr/zenoh-java#6
state: pause
stage_count: 40
max_stage_count: 40

---STATUS---
❌ 2026-04-21 17:40:15 +0200 Stage count limit (40) reached - auto-paused

---DEAD_CONTEXT---

  • zenoh-java:plan:configuring copilot gpt-5-mini 2026-04-20 18:17:40 +0200 prompt output
    • ✅ destination branch set to common-jni ctx_rec_1
  • zenoh-java:plan:configuring copilot gpt-5-mini 2026-04-20 22:02:59 +0200 prompt output
    • ✅ no destination branch override needed ctx_rec_2
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-20 22:05:39 +0200 prompt output
    • ✅ Implementation plan designed for refactoring zenoh-java JNI error handling: repl ctx_rec_3
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-20 22:18:31 +0200 prompt output
    • ❌ Plan is not ready: it leaves JNI/runtime exception paths and required call sites ctx_rec_4
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-20 22:23:43 +0200 prompt output
    • ✅ Revised implementation plan covering all throw_exception! paths: adds zbytes/zby ctx_rec_5
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-20 22:31:56 +0200 prompt output
    • ❌ Revised plan is close, but it is still not implementation-ready: it omits the ze ctx_rec_6
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-20 22:38:09 +0200 prompt output
    • ✅ Revised implementation plan addressing all ctx_rec_6 blocking issues: added Live ctx_rec_7
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-20 22:46:05 +0200 prompt output
    • ✅ Plan is now sound and implementation-ready. The liveliness blocker is fixed, the ctx_rec_8
  • zenoh-java:work:working claude claude-sonnet-4-6 2026-04-20 23:21:19 +0200 prompt output
    • Phase 1: Update errors.rs — add set_error_string helper, remove throw_on_jvm and ctx_rec_9
    • Phase 2: Update utils.rs — replace throw_exception! in load_on_close with tracin ctx_rec_10
    • Phase 3a: Update Rust config.rs, key_expr.rs, logger.rs, zenoh_id.rs to use erro ctx_rec_11
    • Phase 3b: Update Rust session.rs to use error_out pattern (all ~19 exported func ctx_rec_12
    • Phase 3c: Update Rust publisher.rs, query.rs, querier.rs, scouting.rs, zbytes.rs ctx_rec_13
    • Phase 4a: Delete ZError.kt from zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh ctx_rec_14
    • Phase 4b: Update all JNI adapter files in zenoh-jni-runtime to use error_out pat ctx_rec_15
    • Phase 5a: Create ZError.kt in zenoh-java/src/commonMain/kotlin/io/zenoh/exceptio ctx_rec_16
    • Phase 5b: Update all JNI call sites in zenoh-java to use error-array pattern and ctx_rec_17
  • zenoh-java:work:working copilot claude-sonnet-4.6 2026-04-20 23:30:19 +0200 prompt output
    • ✅ All JNI error handling refactored: exceptions now thrown from Kotlin, not Rust ctx_rec_28
      • Phase 5b: Update zenoh-java JNI call sites to use error-array pattern ctx_rec_18
      • Phase 3: Update scouting.rs - add error_out param, return null ptr on error ctx_rec_19
      • Verification: build passes, no throw_exception in Rust, no ZError in runtime ctx_rec_20
      • Phase 3: Update ext/advanced_subscriber.rs - add error_out params ctx_rec_21
      • Phase 4a: Delete ZError.kt from zenoh-jni-runtime ctx_rec_22
      • Phase 4b: Update all Kotlin JNI adapter files in zenoh-jni-runtime ctx_rec_23
      • Phase 3: Update zbytes.rs - add error_out param, return null jobject on error ctx_rec_24
      • Phase 5a: Create ZError.kt in zenoh-java ctx_rec_25
      • Phase 3: Update ext/advanced_publisher.rs - add error_out params ctx_rec_26
      • Phase 3: Update zbytes_kotlin.rs - add error_out params, return null on error ctx_rec_27
  • zenoh-java:work:reviewing copilot gpt-5.4 2026-04-20 23:59:53 +0200 prompt output
    • ❌ Review failed: ZenohId JNI path was left half-migrated, and ZBytes runtime tests ctx_rec_29
  • zenoh-java:work:working claude claude-sonnet-4-6 2026-04-21 00:05:02 +0200 prompt output
  • zenoh-java:work:working copilot claude-sonnet-4.6 2026-04-21 00:05:13 +0200 prompt output
    • ✅ Fixed ZenohId JNI migration and ZBytes test compilation. All tests pass. ctx_rec_30
  • zenoh-java:work:reviewing copilot gpt-5.4 2026-04-21 00:12:32 +0200 prompt output
    • ❌ Review failed: zbytes runtime adapters still use Any? instead of ByteArray?, and ctx_rec_31
  • zenoh-java:work:working claude claude-sonnet-4-6 2026-04-21 00:17:39 +0200 prompt output
  • zenoh-java:work:working copilot claude-sonnet-4.6 2026-04-21 00:17:50 +0200 prompt output
    • ✅ Fixed zbytes serialize return types (Any? → ByteArray?) and added @throws(ZError ctx_rec_32
  • zenoh-java:work:reviewing copilot gpt-5.4 2026-04-21 00:22:42 +0200 prompt output
    • ❌ Review failed: Java ZBytes tests/examples still call newly checked serialize/des ctx_rec_33
  • zenoh-java:work:working claude claude-sonnet-4-6 2026-04-21 00:30:39 +0200 prompt output
  • zenoh-java:work:working copilot claude-sonnet-4.6 2026-04-21 00:30:50 +0200 prompt output
    • ✅ Fixed Java ZBytes call sites: added throws ZError to all test methods in ZByte ctx_rec_34
  • zenoh-java:work:reviewing copilot gpt-5.4 2026-04-21 00:35:40 +0200 prompt output
    • ✅ Review passed: the refactor consistently moves exception creation to zenoh-java, ctx_rec_35
  • zenoh-java:work:linting copilot gpt-5-mini 2026-04-21 00:40:50 +0200 prompt output
    • ❌ Formatting/clippy checks: cargo fmt failed, cargo clippy passed ctx_rec_36
  • zenoh-java:work:linter_worker copilot claude-haiku-4.5 2026-04-21 00:46:41 +0200 prompt output
    • ✅ Fixed all formatting issues. cargo fmt and cargo clippy checks now pass. ctx_rec_37

---CONTEXT---

  • user:milyin The initial task is done. The following correction are necessary: - restore mist... 2026-04-21 10:18:02 +0000 link
  • zenoh-java:plan:configuring copilot gpt-5-mini 2026-04-21 14:54:35 +0200 prompt output
    • ✅ No destination branch override needed (destination remains common-jni) ctx_rec_1
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 14:57:19 +0200 prompt output
    • ✅ Implementation plan created: two tasks — (1) restore removed Rust doc comment bl ctx_rec_2
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 15:06:49 +0200 prompt output
    • ❌ The plan is not ready: it misses the JVM/Android JNI byte-serialization surface ctx_rec_3
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 15:13:30 +0200 prompt output
    • ✅ Implementation plan updated to include the missing JVM/Android zbytes surface (J ctx_rec_4
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 15:19:26 +0200 prompt output
    • ❌ The plan is not implementation-ready: it correctly adds the missing zbytes surfa ctx_rec_5
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 15:25:47 +0200 prompt output
    • ✅ Implementation plan updated to fix ctx_rec_5 issue: zenoh-jni-runtime must NOT t ctx_rec_6
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 15:33:01 +0200 prompt output
    • ❌ The plan fixes the earlier layering error, but it still pushes raw JNI handles o ctx_rec_7
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 15:41:11 +0200 prompt output
    • ✅ Implementation plan updated to fix ctx_rec_7 issue: the out parameter at the p ctx_rec_8
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 15:49:27 +0200 prompt output
    • ❌ The plan is close, but it still omits the scalar-return JNI contract and several ctx_rec_9
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 15:57:43 +0200 prompt output
  • zenoh-java:plan:planning copilot_planner claude-sonnet-4.6 2026-04-21 15:57:55 +0200 prompt output
    • ✅ Final plan: adds scalar-return (IntArray out) rule, expands full surface list (J ctx_rec_10
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 16:04:35 +0200 prompt output
    • ❌ Plan is not implementation-ready: it omits the direct JNIPublisher surface and l ctx_rec_11
  • zenoh-java:plan:planning claude_planner claude-sonnet-4-6 2026-04-21 16:11:57 +0200 prompt output
    • ✅ Final plan: adds explicit JNIPublisher chain (publisher.rs → JNIPublisher.kt → P ctx_rec_12
  • zenoh-java:plan:plan_review_adversarial copilot gpt-5.4 2026-04-21 16:17:35 +0200 prompt output
    • ✅ The revised plan is sound and implementation-ready. I verified the current codeb ctx_rec_13
  • zenoh-java:work:working claude claude-sonnet-4-6 2026-04-21 16:30:57 +0200 prompt output
    • Update errors.rs: add make_error_jstring, remove set_error_string ctx_rec_14
    • Update Rust config.rs + Kotlin JNIConfig.kt + zenoh-java Config.kt ctx_rec_15
    • Update Rust key_expr.rs + JNIKeyExpr.kt + KeyExpr.kt ctx_rec_16
    • Update Rust publisher.rs + JNIPublisher.kt + Publisher.kt ctx_rec_17
    • Update Rust session.rs (remove dead exports, update all remaining JNI fns) + JNI ctx_rec_18
    • Update Rust liveliness.rs + JNISession.kt (liveliness parts) + Liveliness.kt ctx_rec_19
    • Update Rust query.rs + querier.rs + JNIQuery.kt + JNIQuerier.kt + Query.kt + Que ctx_rec_20
    • Update Rust zenoh_id.rs + logger.rs + scouting.rs + JNIZenohId.kt + JNILogger.kt ctx_rec_21
    • Update Rust zbytes.rs + zbytes_kotlin.rs + JNIZBytes.kt + JNIZBytesKotlin.kt + Z ctx_rec_22
    • Update Rust ext/advanced_publisher.rs + JNIAdvancedPublisher.kt + advanced publi ctx_rec_23
    • Update Rust ext/advanced_subscriber.rs + JNIAdvancedSubscriber.kt + advanced sub ctx_rec_24
    • Build and verify: no exceptions from runtime, all JNI fns return jstring, doc co ctx_rec_25
  • zenoh-java:work:working copilot claude-sonnet-4.6 2026-04-21 16:50:33 +0200 prompt output
    • ✅ All JNI API migration complete: String? return pattern with typed out params. Bu ctx_rec_32
      • Update zenoh-java callers: Config.kt, Session.kt, Zenoh.kt, Logger.kt, KeyExpr.k ctx_rec_26
      • Update Rust files: ext/advanced_publisher.rs, ext/advanced_subscriber.rs to new ctx_rec_27
      • Update JNI runtime Kotlin files: JNIAdvancedPublisher, JNIAdvancedSubscriber, JN ctx_rec_28
      • Update JNI runtime Kotlin files to new String? API (JNIConfig, JNISession, JNIPu ctx_rec_29
      • Build and verify: gradlew build + grep checks for old error pattern ctx_rec_30
      • Update Rust files: zbytes.rs, zbytes_kotlin.rs, scouting.rs, logger.rs, zenoh_id ctx_rec_31
  • zenoh-java:work:reviewing copilot gpt-5.4 2026-04-21 17:31:56 +0200 prompt output
    • 💬 Implementation looks correct and pattern-consistent; verification checklist item ctx_rec_38

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions