-
Notifications
You must be signed in to change notification settings - Fork 338
handle runtime exception gracefully #1234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,4 +98,36 @@ public void run() { | |||||||||||||||||||||||||||||||||||||||||
| throw instance[0]; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Issue 1231. | ||||||||||||||||||||||||||||||||||||||||||
| * <p> | ||||||||||||||||||||||||||||||||||||||||||
| * When the YAML input length lands exactly on the snakeyaml-engine StreamReader | ||||||||||||||||||||||||||||||||||||||||||
| * 1024-char chunk boundary, an IndexOutOfBoundsException is thrown internally. | ||||||||||||||||||||||||||||||||||||||||||
| * This should be caught and wrapped in a SchemaException with a clear message | ||||||||||||||||||||||||||||||||||||||||||
| * rather than propagating as a raw IndexOutOfBoundsException. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||
| void yamlInputAtChunkBoundaryShouldThrowSchemaException() { | ||||||||||||||||||||||||||||||||||||||||||
| // Build a YAML key that is exactly 1024 chars so the total YAML content | ||||||||||||||||||||||||||||||||||||||||||
| // hits the snakeyaml-engine StreamReader boundary. | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+105
to
+113
|
||||||||||||||||||||||||||||||||||||||||||
| * When the YAML input length lands exactly on the snakeyaml-engine StreamReader | |
| * 1024-char chunk boundary, an IndexOutOfBoundsException is thrown internally. | |
| * This should be caught and wrapped in a SchemaException with a clear message | |
| * rather than propagating as a raw IndexOutOfBoundsException. | |
| */ | |
| @Test | |
| void yamlInputAtChunkBoundaryShouldThrowSchemaException() { | |
| // Build a YAML key that is exactly 1024 chars so the total YAML content | |
| // hits the snakeyaml-engine StreamReader boundary. | |
| * When the YAML key length (so that the colon/token position) lands exactly on | |
| * the snakeyaml-engine StreamReader 1024-char chunk boundary, an | |
| * IndexOutOfBoundsException is thrown internally. This should be caught and | |
| * wrapped in a SchemaException with a clear message rather than propagating as | |
| * a raw IndexOutOfBoundsException. | |
| */ | |
| @Test | |
| void yamlInputAtChunkBoundaryShouldThrowSchemaException() { | |
| // Build a YAML key that is exactly 1024 chars so that the colon falls on | |
| // the snakeyaml-engine StreamReader 1024-char chunk boundary (the overall | |
| // YAML input is therefore slightly longer than 1024 characters). |
Copilot
AI
Mar 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will pass even if schema.validate(...) does not throw at all, and it also treats any RuntimeException as acceptable (including unrelated NullPointerException, etc.). To make this a reliable regression test for issue 1231, assert that a SchemaException is thrown (and ideally assert its message/prefix), and fail the test when no exception is thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deserialize(AbsoluteIri, ...)deliberately throws anUncheckedIOExceptionwhen the resource isn't found, but the newcatch (RuntimeException e)will wrap that into aSchemaExceptionwith an "Invalid ... input" message. This changes the exception type/semantics for missing resources and makes the message misleading. HandleUncheckedIOExceptionseparately (rethrow) or narrow the runtime wrapping to the specific parser exceptions you intend to convert.