Repository navigation
Restore IonException for malformed text input - #1185
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1185 +/- ##
============================================
+ Coverage 67.23% 68.38% +1.14%
- Complexity 5484 5738 +254
============================================
Files 159 160 +1
Lines 23025 23497 +472
Branches 4126 4232 +106
============================================
+ Hits 15481 16068 +587
+ Misses 6262 6129 -133
- Partials 1282 1300 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Since closing a text reader started clearing its current value (amazon-ion#1178), a lob or quoted field name that failed to decode surfaced as an AssertionError, or an IllegalArgumentException without -ea, hiding the IonException callers handle. Leaving the reader as it was before the failed read also lets it read on or be retried.
eb91793 to
62809ac
Compare
| // A triple-quoted clob read a byte at a time fails even when it is valid, a separate problem. | ||
| lobs.add("{{'''x\\q'''}} 7"); |
| byte[] bytes = _Private_Utils.loadFileBytes(myTestFile); | ||
| try | ||
| { | ||
| loader().load(bytes); | ||
| fail("Expected IonException"); | ||
| } | ||
| catch (IonException e) { /* good */ } |
There was a problem hiding this comment.
Rephrase using assertThrows?
| try { | ||
| system.getLoader().load(reader); | ||
| fail("Expected IonException for " + ion); | ||
| } catch (IonException e) { | ||
| message = e.getMessage(); | ||
| } |
| try { | ||
| reader.close(); | ||
| } catch (Throwable t) { | ||
| throw new AssertionError("close() after the IonException for " + ion + " threw " + t, t); | ||
| } |
There was a problem hiding this comment.
This catch is unnecessary, as an exception thrown from close() here will fail the test (as desired).
| try { | ||
| system.singleValue(bytes); | ||
| fail("Expected IonException for " + ion); | ||
| } catch (IonException e) { | ||
| assertEquals("IonException from singleValue(byte[]) for " + ion, message, e.getMessage()); | ||
| } |
The hand-rolled checks obscured what each test expects, and an exception from close() already fails the test without extra handling. Addresses review on amazon-ion#1185
So the case the test leaves out points at the issue that tracks it instead of an unexplained note. Addresses review on amazon-ion#1185
|
@tgregg I ran the benchmarks from #1172's description against Setup. ms/op, lower is better, ± the 99.9% confidence interval:
The streaming Since these datasets have few large blobs or quoted field names, I also timed those two paths directly, in the same rough way as #1172 (best of 5 after 2 warm-ups, not JMH):
Run to run, the same build varied by up to about 8% in these. That fits the bytecode: in |
Issue #, if available: N/A — regression in v1.12.2 from #1178.
Description of changes:
Problem
In 1.12.2, when the text reader fails to decode a malformed blob, clob or quoted field name and is then closed, the caller gets an internal error instead of the
IonException:java.lang.AssertionErroratUnifiedSavePointManagerX$SavePoint.clear(UnifiedSavePointManagerX.java:318)IllegalArgumentException: you can't release an active save pointIonSystem.singleValue(byte[])andIonLoader.load(byte[])close the reader in afinallyblock, so they hit this on input like{a:{{invalid_blob}}}:Bisect: v1.12.1 and
ab9cfeab~1throwIonException;ab9cfeab(#1178) throwsAssertionError.Cause
IonReaderTextSystemX.load_lob_contents()andIonReaderTextRawX.token_contents_load()activate the value's save point, decode it, then deactivate it. A decode error skipped the deactivation, leaving the save point active. #1178 madeclose()callclear_value(), which clears that still-active save point, and the error thrown fromclose()replaces theIonException. The same leftover state also madenext()or a secondnewBytes()after the error fail withAssertionError, already in 1.12.1.Change
finallyblock at both places.close()is unchanged, so Treat a closed text reader as at end of stream #1178's closed-reader behaviour stays as it is.clear_value()fromclose()fails Treat a closed text reader as at end of stream #1178'stestTextReaderInsideStructIsAtEndAfterClose(getType()afterclose()returnsSTRING); ending the active save point insideclose()fixesclose()only, notnext()or a retry after the error.Tests
IonReaderCloseableTest.testTextReaderClosesAfterMalformedValue: malformed lobs and quoted field names fromStringandbyte[];close()succeeds andnext()then returnsnull;singleValue(byte[])throws the sameIonExceptionmessage as reading without closing.IonReaderTextFastPathsTest.malformedValuesLeaveTheReaderUsable: for everySource(bytes, streams including 1- and 4093-byte reads, string, reader), including values longer than a page: reading the malformed value throwsIonException, reading it again throwsIonException, the reader moves on to the next value, andclose()succeeds.BadIonTest.testLoadBytes: loads the ion-tests bad corpus throughload(byte[]), which closes the reader. The existingload(File)andload(String)paths do not close it, which is why the corpus did not catch this regression. 58 of its 986 cases fail without the fix.Each new test fails without the main-source change, and reverting either of the two
finallyblocks alone fails the tests again../gradlew checkpasses: 199,645 tests, 0 failures, 586 skipped.Not addressed here (pre-existing in 1.12.1; to be filed separately)
skip_over_lobitself throws (e.g.{{abcd}x), a secondnewBytes()fails an assertion inload_lob_save_point.{{'''abc'''}}) read from a stream that returns a few bytes per read throwsIllegalArgumentException: end point ... must be within 1 page.{a:"x\q", b:"yz"}), the next field name is read asxb.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.