Repository navigation
Make the #367 parse-error fallback work for jars without PolicyParseException - #377
Merged
muditchaudhary merged 1 commit intoNov 16, 2026
Conversation
muditchaudhary
marked this pull request as ready for review
November 9, 2026 19:07
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
muditchaudhary
force-pushed
the
ffi-parse-exception-fallback
branch
from
November 9, 2026 19:12
4817211 to
4fca6cc
Compare
jtbrain
approved these changes
Nov 9, 2026
| if env.exception_clear().is_err() { | ||
| return; | ||
| } | ||
| let missing_class = env |
Contributor
There was a problem hiding this comment.
We could be stronger than NoClassDefFoundError here and catch java/lang/LinkageError since that's the parent to that as well as the sibling NoSuchMethodError, but since we only expect NoClassDefFoundError, this should be fine imo.
| /// leaves a `NoClassDefFoundError` pending. Clear it, so that such a jar gets the | ||
| /// `InternalException` it has always received for a parse error. Any other pending exception, | ||
| /// such as an `OutOfMemoryError`, is put back to propagate. | ||
| fn clear_missing_class_error(env: &mut JNIEnv<'_>) { |
Contributor
There was a problem hiding this comment.
Nit: should we add a unit test covering this fallback behavior?
Something like
- Call
env.find_class("com/cedarpolicy/DoesNotExist"), thenclear_missing_class_error, and assert!exception_check(). - Call
throw_new("java/lang/IllegalStateException", ..), thenclear_missing_class_error, and assert the exception is still pending and is the same class.
mark-creamer-amazon
approved these changes
Nov 9, 2026
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.
Make the #367 parse-error fallback work for jars without
PolicyParseExceptionSummary
#367 added
PolicyParseException, which the native library constructs whenPolicySet.parsePoliciesfails toparse policy text. It was meant to stay backward compatible: if building the richer exception failed, the code
fell back to the generic path:
That fallback never worked for the case it needed to cover.
The problem
When the jar has no
PolicyParseException:build_parse_exceptionfails to look up the class, which leaves aNoClassDefFoundErrorpending in the JVM,and returns
Err.throw_parse_errorsfalls back tothrow_internal, as Surface structured parse diagnostics from PolicySet.parsePolicies #367 intended.throw_internalreturns without throwing anything whenever an exception is already pending, so theNoClassDefFoundErroris what reaches Java.So instead of the
InternalExceptionit has always received, the caller ofPolicySet.parsePoliciesgets aNoClassDefFoundError. That's anError, so acatch (InternalException e)doesn't catch it, and the parseerror itself is lost.
The fix
A new
clear_missing_class_errorruns before the fallback callsthrow_internal:IsInstanceOfmay not be called while one is pending.NoClassDefFoundError, it stays cleared.throw_internalthen throwsInternalException("Internal JNI Error: <parse errors>"), the same class and message as before Surface structured parse diagnostics from PolicySet.parsePolicies #367.OutOfMemoryError) is put back unchanged and propagates as before.Jars that include
PolicyParseExceptionare unaffected and still get the full exception with Cedar's structureddiagnostics.
Behaviour for an older jar
InternalExceptionNoClassDefFoundErrorInternalExceptionInternal JNI Error: <errors>com/cedarpolicy/model/exception/PolicyParseExceptionInternal JNI Error: <errors>The text of
<errors>comes from the Cedar version the native library was built with.Also in this PR
CHANGELOG.mdsections onmainnow match the 4.11.0 release.Testing
PolicyParseException*.class, in a separate JVMagainst the new native library. Without the fix,
parsePolicieson invalid text throwsjava.lang.NoClassDefFoundError: com/cedarpolicy/model/exception/PolicyParseException. With the fix, it throwsInternalExceptionwith messageInternal error: Internal JNI Error: unexpected token \::``.PolicyParseDiagnosticsTestspass, so a current jar still getsPolicyParseException../gradlew build,cargo test --all-features,cargo fmt --checkandcargo clippy --all-features --all-targetsall pass.Also updates