fixes isInStruct/getFieldName/getFieldNameSymbol behavior for DOM-backed readers#134
fixes isInStruct/getFieldName/getFieldNameSymbol behavior for DOM-backed readers#134
Conversation
| iw.writeValue(ir); | ||
| iw.stepOut(); | ||
| assertEquals(data, reloadSingleValue()); | ||
| iw.writeValue(ir); // should throw IllegalStateException ("Field name not set") |
There was a problem hiding this comment.
We've been starting to shift to using JUnit's ExpectedException (instead of @Test(expected=...)) so that the particular line where the exception is expected may be isolated.
| public boolean isInStruct() | ||
| { | ||
| return (_parent instanceof IonStruct); | ||
| return getDepth() > 0 && _parent instanceof IonStruct; |
There was a problem hiding this comment.
When a DOM value is provided to a reader, shouldn't the reader's public getDepth() method restart at zero for that value? It should also be impossible to stepOut past that depth.
There was a problem hiding this comment.
Agreed, getDepth() should start at zero when a reader is constructed over a DOM -- and it already does. This change leverages that fact to fix the behavior of isInStruct() such that it initially returns false when a reader is constructed over a DOM.
And attempts to stepOut() to a parent of the DOM value already results in an IllegalStateException.
For a test (albeit a very terse one) that asserts the expected behavior, see TreeReaderTest.testReadingStructFields().
Fix for #133