From 4781fdd874b09d131fc01d88af9825ebd4aed12a Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:23:24 -0700 Subject: [PATCH] Fix NPE in IonRawBinaryWriter (#574) --- src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java | 1 + test/com/amazon/ion/impl/bin/IonRawBinaryWriterTest.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java b/src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java index 2ec21cc886..e5bda78333 100644 --- a/src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java +++ b/src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java @@ -586,6 +586,7 @@ public void setTypeAnnotationSymbols(final SymbolToken... annotations) { for (final SymbolToken annotation : annotations) { + if (annotation == null) break; addTypeAnnotationSymbol(annotation.getSid()); } } diff --git a/test/com/amazon/ion/impl/bin/IonRawBinaryWriterTest.java b/test/com/amazon/ion/impl/bin/IonRawBinaryWriterTest.java index 7d23e59afc..ddf49e9969 100644 --- a/test/com/amazon/ion/impl/bin/IonRawBinaryWriterTest.java +++ b/test/com/amazon/ion/impl/bin/IonRawBinaryWriterTest.java @@ -425,6 +425,13 @@ public void testSetAnnotations() throws Exception assertValue("name::version::'''foobar'''"); } + @Test + public void testSetTypeAnnotationSymbolsWithNullInArray() throws IOException { + writer.setTypeAnnotationSymbols(systemSymbol(NAME_SID), null); + writer.writeBool(true); + assertValue("name::true"); + } + @Test public void testList() throws Exception {