From cedfd619866ee2d3a1b9a74bc5540697aa0e275d Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Wed, 14 Sep 2016 14:49:56 +0200 Subject: Fix ClassifySession read NPE when NodeContext is missing Change-Id: Ieca5ad125df5f26f82351871a0238e65be3e300c Signed-off-by: Marek Gradzki --- .../v3po/vppclassifier/VppClassifierContextManagerImpl.java | 7 ++++++- .../v3po/vppclassifier/VppClassifierContextManagerImplTest.java | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'v3po') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImpl.java index 9f61ab021..e1bf50107 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImpl.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImpl.java @@ -28,6 +28,7 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.BindingBrokerReader; +import java.util.List; import java.util.stream.Collector; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -149,7 +150,11 @@ public final class VppClassifierContextManagerImpl implements VppClassifierConte } final String tableName = getTableName(tableIndex, ctx); final Optional tableCtx = ctx.read(getMappingIid(tableName)); - return Optional.fromNullable(tableCtx.get().getNodeContext().stream() + final List nodeContext = tableCtx.get().getNodeContext(); + if (nodeContext == null) { + return Optional.absent(); + } + return Optional.fromNullable(nodeContext.stream() .filter(n -> n.getIndex().equals(nodeIndex)) .findFirst() .map(nodes -> nodes.getName()) diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java index cbc0c3802..3e198e002 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java @@ -119,6 +119,14 @@ public class VppClassifierContextManagerImplTest { assertFalse(vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx).isPresent()); } + @Test + public void testGetNodeNameMissingNodeCtx() throws Exception { + final ClassifyTableContext tableCtx = table(TABLE_ID_0, TABLE_NAME_0, "aa"); + when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(tableCtx))); + when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(tableCtx)); + assertEquals(Optional.absent(), vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx)); + } + @Test public void testGetNodeName() throws Exception { final ClassifyTableContext tableCtx = table(TABLE_ID_0, TABLE_NAME_0, "aa", node("node123", 123)); -- cgit 1.2.3-korg