Skip to content

Commit

Permalink
Account for missing system symbol table (amazon-ion#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobarr-amzn authored Oct 3, 2024
1 parent 171aebd commit 76276cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ion-tests
Submodule ion-tests updated 636 files
16 changes: 9 additions & 7 deletions src/main/java/com/amazon/ion/impl/LocalSymbolTableImports.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,15 @@ SymbolTable getSystemSymbolTable()
*/
SymbolTable[] getImportedTables()
{
int count = myImports.length - 1; // we don't include system symtab
SymbolTable[] imports = new SymbolTable[count];
if (count > 0)
{
// defensive copy
System.arraycopy(myImports, 1, imports, 0, count);
}
// We have only the system symbol table, or we have none.
// None implies an empty system symbol table, as in Ion 1.1.
if (myImports.length == 1 || myImports.length == 0) return new SymbolTable[0];

int nonSystemTables = myImports.length - 1; // we don't include system symtab

SymbolTable[] imports = new SymbolTable[nonSystemTables];
// defensive copy
System.arraycopy(myImports, 1, imports, 0, nonSystemTables);
return imports;
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/amazon/ion/impl/LocalSymbolTableImportsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.junit.jupiter.api.Test

internal class LocalSymbolTableImportsTest {
@Test
fun `EMPTY#getImportedTables should be empty`() {
assertThat(LocalSymbolTableImports.EMPTY.importedTables, Matchers.emptyArray())
}
}

0 comments on commit 76276cf

Please sign in to comment.