From 32b5b25fb14f6eafae8447a4eaae8fc77dc6b048 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Mon, 24 Jun 2024 14:15:46 +0300 Subject: [PATCH 1/2] Reproducer for #912 - JSONWire cannot resume parsing after ignoring missing alias object --- .../openhft/chronicle/wire/AbstractUntypedFieldTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java b/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java index 3806916b65..4eff83bb5c 100644 --- a/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java +++ b/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java @@ -54,7 +54,8 @@ void typedFieldsShouldBeNonNull(Function, Wire> wireConstruction) final Bytes bytes = Bytes.from("" + "!net.openhft.chronicle.wire.AbstractUntypedFieldShouldBeNull$Holder {\n" + " a: !AImpl {\n" + - " }\n" + + " }," + + " \"b\": \"Impl\",\n" + "}"); final Wire textWire = wireConstruction.apply(bytes); @@ -72,7 +73,8 @@ void typedFieldsShouldBeNonNull(Function, Wire> wireConstruction) void untypedFieldsShouldBeNull(Function, Wire> wireConstruction) { final Bytes bytes = Bytes.from("!net.openhft.chronicle.wire.AbstractUntypedFieldShouldBeNull$Holder {\n" + " a: {\n" + - " }\n" + + " }," + + " \"b\": \"Abstract\",\n" + "}"); final Wire textWire = wireConstruction.apply(bytes); @@ -112,6 +114,7 @@ private static final class AImpl extends A { // Holder class to hold instances of type A private static final class Holder { A a; + String b; } } From 1ed63531f5ed481fd118fee182e891c2e191c7a2 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Mon, 24 Jun 2024 15:15:18 +0300 Subject: [PATCH 2/2] Better test, exception matching improvement --- src/main/java/net/openhft/chronicle/wire/WireMarshaller.java | 3 ++- .../net/openhft/chronicle/wire/AbstractUntypedFieldTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/wire/WireMarshaller.java b/src/main/java/net/openhft/chronicle/wire/WireMarshaller.java index 8822626a42..ec288656a6 100644 --- a/src/main/java/net/openhft/chronicle/wire/WireMarshaller.java +++ b/src/main/java/net/openhft/chronicle/wire/WireMarshaller.java @@ -1433,7 +1433,7 @@ protected void setValue(Object o, @NotNull ValueIn read, boolean overwrite) thro Object object = null; try { object = read.object(using, type, false); - } catch (Exception e) { + } catch (ClassNotFoundRuntimeException e) { // "Unhandled" Abstract classes that are not types should be null (Enums are abstract classes in Java but should not be null here) if (using == null && Modifier.isAbstract(type.getModifiers()) && @@ -1441,6 +1441,7 @@ protected void setValue(Object o, @NotNull ValueIn read, boolean overwrite) thro !type.isEnum() && !read.isTyped()) { // retain the null value of object + read.wireIn().bytes().readPosition(pos); Jvm.warn().on(getClass(), "Ignoring exception and setting field '" + field.getName() + "' to null", e); } else { Jvm.rethrow(e); diff --git a/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java b/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java index 4eff83bb5c..36ab759daa 100644 --- a/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java +++ b/src/test/java/net/openhft/chronicle/wire/AbstractUntypedFieldTest.java @@ -53,7 +53,7 @@ void beforeEach() { void typedFieldsShouldBeNonNull(Function, Wire> wireConstruction) { final Bytes bytes = Bytes.from("" + "!net.openhft.chronicle.wire.AbstractUntypedFieldShouldBeNull$Holder {\n" + - " a: !AImpl {\n" + + " \"a\": !AImpl {\n" + " }," + " \"b\": \"Impl\",\n" + "}"); @@ -72,7 +72,7 @@ void typedFieldsShouldBeNonNull(Function, Wire> wireConstruction) @MethodSource("provideWire") void untypedFieldsShouldBeNull(Function, Wire> wireConstruction) { final Bytes bytes = Bytes.from("!net.openhft.chronicle.wire.AbstractUntypedFieldShouldBeNull$Holder {\n" + - " a: {\n" + + " \"a\": {\n" + " }," + " \"b\": \"Abstract\",\n" + "}");