amazon-ion / ion-java

Java streaming parser/serializer for Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
864 stars 110 forks source link

Transcribing from Ion 1.1 binary to Ion 1.0 text fails #952

Closed jobarr-amzn closed 3 days ago

jobarr-amzn commented 3 days ago

It looks like LocalSymbolTableImports.getImportedTables fails when the system symbol table is not carried as the first "imported" symbol table in myImports.

The following test fails:

    @Test
    public void testTranscribe() throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IonWriter writer = IonEncodingVersion.ION_1_1.binaryWriterBuilder().build(baos);
        writer.writeString("hello world");
        writer.close();

        IonReader reader = IonReaderBuilder.standard().build(baos.toByteArray());
        IonWriter sink = IonEncodingVersion.ION_1_0.textWriterBuilder().build(baos);

        sink.writeValues(reader);
    }

Stack trace:

java.lang.NegativeArraySizeException
    at com.amazon.ion.impl.LocalSymbolTableImports.getImportedTables(LocalSymbolTableImports.java:246)
    at com.amazon.ion.impl.LocalSymbolTable.getImportedTables(LocalSymbolTable.java:591)
    at com.amazon.ion.impl.IonWriterSystemText.writeLocalSymtab(IonWriterSystemText.java:421)
    at com.amazon.ion.impl.IonWriterUser.setSymbolTable(IonWriterUser.java:308)
    at com.amazon.ion.impl._Private_IonWriterBase.transfer_symbol_tables(_Private_IonWriterBase.java:313)
    at com.amazon.ion.impl._Private_IonWriterBase.writeValues(_Private_IonWriterBase.java:294)
    at com.amazon.coral.metrics.reporter.BinaryFragmentWriterTest.testTranscribe(BinaryFragmentWriterTest.java:76)
    at <many lines of JUnit stack elided>