diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-11-29 17:10:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 17:10:55 +0100 |
commit | d7fbd40aad2080adf7033e8f668e5218ab12bace (patch) | |
tree | 0b7c8e4f0a8427a6eccdeb19882ce90ccbdd852c /src/main/java/org/uic/barcode/asn1 | |
parent | Merge pull request #35 from UnionInternationalCheminsdeFer/1.2.8 (diff) | |
parent | additional tests (diff) | |
download | UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar.gz UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar.bz2 UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar.lz UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar.xz UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.tar.zst UIC-barcode-d7fbd40aad2080adf7033e8f668e5218ab12bace.zip |
Diffstat (limited to 'src/main/java/org/uic/barcode/asn1')
-rw-r--r-- | src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java | 12 | ||||
-rw-r--r-- | src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java | 9 |
2 files changed, 19 insertions, 2 deletions
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 <T> 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 <T> 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; |