diff --git a/src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java b/src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java index 61e09041e..de2cfb9ce 100644 --- a/src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java +++ b/src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java @@ -1,18 +1,5 @@ -/* - * Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 package com.amazon.ion.impl; import static com.amazon.ion.SystemSymbols.ION_1_0; @@ -267,6 +254,7 @@ private static final class IonReaderTextSpan implements Span, TextSpan, OffsetSpan { private final UnifiedDataPageX _data_page; + private final SymbolTable _symbols; private final IonType _container_type; private final long _start_offset; @@ -284,6 +272,7 @@ private static final class IonReaderTextSpan // page of buffered input Which is the case for the time // being. Later, when this is stream aware, this needs to change. _data_page = current_stream._buffer.getCurrentPage(); + _symbols = reader.getSymbolTable(); _container_type = reader.getContainerType(); _start_offset = reader._value_start_offset - reader._physical_start_offset; @@ -391,6 +380,7 @@ private void hoistImpl(Span span) } IonType container = text_span.getContainerType(); re_init(iis, container, text_span._start_line, text_span._start_column); + _symbols = text_span._symbols; } diff --git a/src/test/java/com/amazon/ion/TextSpanHoistingTest.java b/src/test/java/com/amazon/ion/TextSpanHoistingTest.java new file mode 100644 index 000000000..a577fcf68 --- /dev/null +++ b/src/test/java/com/amazon/ion/TextSpanHoistingTest.java @@ -0,0 +1,50 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +package com.amazon.ion; + +import com.amazon.ion.facet.Facets; +import com.amazon.ion.system.IonReaderBuilder; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import java.io.IOException; + +public class TextSpanHoistingTest +{ + @Test + public void hoistingTextSpanAlsoHoistsSymbolTable() throws IOException { + String textWithSymbolTables = + "$ion_1_0 $ion_symbol_table::{ symbols:[\"bar\"] } { foo1: $10 }" + + "$ion_1_0 $ion_symbol_table::{ symbols:[\"baz\"] } { foo2: $10 }"; + + IonReader reader = IonReaderBuilder.standard().build(textWithSymbolTables); + SeekableReader seekableReader = Facets.asFacet(SeekableReader.class, reader); + + Assertions.assertEquals(IonType.STRUCT, reader.next()); + Span span = seekableReader.currentSpan(); + reader.stepIn(); + Assertions.assertEquals(IonType.SYMBOL, reader.next()); + Assertions.assertEquals("foo1", reader.getFieldName()); + Assertions.assertEquals("bar", reader.stringValue()); + reader.stepOut(); + + Assertions.assertEquals(IonType.STRUCT, reader.next()); + reader.stepIn(); + Assertions.assertEquals(IonType.SYMBOL, reader.next()); + Assertions.assertEquals("foo2", reader.getFieldName()); + Assertions.assertEquals("baz", reader.stringValue()); + reader.stepOut(); + + // now re-seek to the first value + seekableReader.hoist(span); + + Assertions.assertEquals(IonType.STRUCT, reader.next()); + reader.stepIn(); + Assertions.assertEquals(IonType.SYMBOL, reader.next()); + Assertions.assertEquals("foo1", reader.getFieldName()); + + // this assertion fails + Assertions.assertEquals("bar", reader.stringValue()); + reader.stepOut(); + } +}