summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/uic/barcode/asn1')
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/SequenceCoder.java12
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java9
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;