Skip to content

Commit 359db5a

Browse files
authored
Fix check for IVM in writeSymbol/writeSymbolToken (#1142)
1 parent b33e1e4 commit 359db5a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/main/java/com/amazon/ion/impl/IonManagedWriter_1_1.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,10 @@ internal class IonManagedWriter_1_1(
317317
override fun writeSymbol(content: String?) {
318318
val container = containers.peek()
319319
if (container.childIsTaggedValue()) {
320+
val numAnnotations = this.numAnnotations // Store before writeTaggedValueFieldNameAndAnnotations resets to 0
320321
writeTaggedValueFieldNameAndAnnotations()
321322
content.writeMaybeNull(IonType.SYMBOL) {
322-
if (numAnnotations > 0 && depth == 0 && ION_VERSION_MARKER_REGEX.matches(it)) {
323+
if (numAnnotations == 0 && depth == 0 && ION_VERSION_MARKER_REGEX.matches(it)) {
323324
throw IonException("Can't write a top-level symbol that is the same as an IVM.")
324325
}
325326
handleSymbolToken(UNKNOWN_SYMBOL_ID, it, SymbolKind.VALUE, userData)
@@ -343,10 +344,11 @@ internal class IonManagedWriter_1_1(
343344
val container = containers.peek()
344345
if (content?.text != null) return writeSymbol(content.text)
345346
if (container.childIsTaggedValue()) {
347+
val numAnnotations = this.numAnnotations // Store before writeTaggedValueFieldNameAndAnnotations resets to 0
346348
writeTaggedValueFieldNameAndAnnotations()
347349
content.writeMaybeNull(IonType.SYMBOL) {
348350
// TODO: Check to see if the SID refers to a user symbol with text that looks like an IVM
349-
if (it.sid == SystemSymbols.ION_SYMBOL_TABLE_SID) {
351+
if (numAnnotations == 0 && depth == 0 && it.sid == SystemSymbols.ION_1_0_SID) {
350352
throw IonException("Can't write a top-level symbol that is the same as an IVM.")
351353
}
352354
handleSymbolToken(it.sid, it.text, SymbolKind.VALUE, userData)

0 commit comments

Comments
 (0)