From e10588931164ad78e236f072de870780ae6703c5 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 29 Nov 2021 17:09:46 +0100 Subject: additional tests bug fixes on: - voucher - delay confirmation - parking --- src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java | 12 +++++++++++- src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/uic/barcode/asn1') diff --git a/src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java b/src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java index 5e8386e..ce89a3e 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java @@ -13,6 +13,11 @@ import org.uic.barcode.asn1.uper.UperEncoder.Asn1ContainerFieldSorter; class SequenceCoder implements Decoder, Encoder { @Override public boolean canEncode(T obj, Annotation[] extraAnnotations) { + + if (obj == null || obj.getClass() == null) { + return false; + } + Class type = obj.getClass(); AnnotationStore annotations = new AnnotationStore(type.getAnnotations(), extraAnnotations); @@ -53,7 +58,12 @@ class SequenceCoder implements Decoder, Encoder { pos = String.format("Position: %d.%d", bitbuffer.position()/8 , bitbuffer.position() % 8); UperEncoder.logger.debug(String.format("%s: Field %s", pos, f.getName())); try { - UperEncoder.encode2(bitbuffer, f.get(obj), f.getAnnotations()); + Object o = f.get(obj); + if (o != null) { + UperEncoder.encode2(bitbuffer, f.get(obj), f.getAnnotations()); + } else { + throw new Asn1EncodingException("missing object " + f.getName()); + } } catch (Asn1EncodingException e) { throw new Asn1EncodingException("." + f.getName(), e); } catch (IllegalArgumentException e) { diff --git a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java index bba64e2..d5c5d1e 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java @@ -89,7 +89,14 @@ public final class UperEncoder { static void encode2(BitBuffer bitbuffer, T obj, Annotation[] extraAnnotations) throws Asn1EncodingException { - for (Encoder e : encoders) { + + if (obj == null) { + logger.debug(String.format("Object missing")); + return; + } + + + for (Encoder e : encoders) { if (e.canEncode(obj, extraAnnotations)) { e.encode(bitbuffer, obj, extraAnnotations); return; -- cgit v1.2.3