Skip to content

Fix: JNI error path cleanup - #129

Open
redaranj wants to merge 3 commits into
fix/utf8-string-bridgingfrom
fix/jni-error-path-cleanup
Open

Fix: JNI error path cleanup#129
redaranj wants to merge 3 commits into
fix/utf8-string-bridgingfrom
fix/jni-error-path-cleanup

Conversation

@redaranj

Copy link
Copy Markdown
Member

Changes in this pull request

Checks every JNI call in the HTTP resolver trampoline and routes the last two raw failure paths (Stream creation, C2PA.version()) through C2PAError, so nothing in the JNI throws RuntimeException or leaves an exception pending. Also aligns test-shared minSdk to 28.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • All applicable changes have been documented
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment

redaranj and others added 3 commits August 21, 2026 08:03
The resolver body only checked for a pending exception after the
resolve() call itself. The request-side conversions (string transcoding,
body array allocation and copy) and the response-side getters
(getStatus, getBody, the body copy) were unchecked, so an app-side
exception there left the JVM with an exception pending across further
JNI calls, which is undefined behavior, and let a garbage status or body
reach the core.

Check each step: marshalling failures skip the bridge call, and every
response read stashes a pending exception for the outer boundary,
releases its local refs and the half-built body buffer, sets a specific
core error string, and returns -1.

Co-Authored-By: Claude Fable 5 <[email protected]>
Stream creation threw a raw RuntimeException from the JNI when the core
could not allocate a stream, and C2PA.version() was declared non-null
although the string bridge returns NULL on allocation failure, which
would have surfaced as a NullPointerException. Both were left over from
the sentinel-return conversion because neither had a wrapper declaring
C2PAError.

Return 0 from createStreamNative and raise C2PAError.Api from the Stream
constructor; make the version bridge nullable behind a C2PA.version()
wrapper that raises C2PAError.Api. The JNI no longer throws
RuntimeException anywhere, and every external declaration returning an
object type is nullable.

Co-Authored-By: Claude Fable 5 <[email protected]>
test-shared declared minSdk 26 while the library and both apps declare
28, the documented minimum. The apps' manifest merge already took the
higher value, so this only stops lint in test-shared from accepting
API 26 assumptions the library does not support.

Co-Authored-By: Claude Fable 5 <[email protected]>
@redaranj
redaranj requested a review from scouten-adobe August 21, 2026 08:12
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.14%. Comparing base (c4b28a2) to head (3fff617).

Files with missing lines Patch % Lines
...brary/src/main/kotlin/org/contentauth/c2pa/C2PA.kt 0.00% 1 Missing and 1 partial ⚠️
...ary/src/main/kotlin/org/contentauth/c2pa/Stream.kt 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##             fix/utf8-string-bridging     #129      +/-   ##
==============================================================
- Coverage                       72.25%   72.14%   -0.12%     
  Complexity                         38       38              
==============================================================
  Files                              62       62              
  Lines                            2350     2355       +5     
  Branches                          286      289       +3     
==============================================================
+ Hits                             1698     1699       +1     
- Misses                            493      495       +2     
- Partials                          159      161       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant