From 2fed6dbef019e6dee4788c9d4f0dd79e9c592b36 Mon Sep 17 00:00:00 2001 From: Tim F <120514393+tim-aero@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:38:05 -0600 Subject: [PATCH] NPE using refs with the YAML file Whilst references work correctly with annotations, they would throw a NullPointerException when being used with an external configuration such as a YAML file. The issue was caused by the `BatchLoad` property which was initialized by default to true on the annotation but was left as null if not specified in the file --- .../aerospike/mapper/tools/configuration/ClassConfig.java | 4 ++-- .../mapper/tools/configuration/ReferenceConfig.java | 3 ++- .../java/com/aerospike/mapper/tools/utils/TypeUtils.java | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aerospike/mapper/tools/configuration/ClassConfig.java b/src/main/java/com/aerospike/mapper/tools/configuration/ClassConfig.java index d5da40e..9b23975 100644 --- a/src/main/java/com/aerospike/mapper/tools/configuration/ClassConfig.java +++ b/src/main/java/com/aerospike/mapper/tools/configuration/ClassConfig.java @@ -279,12 +279,12 @@ public Builder mappingToBin(String name) { } public Builder beingReferencedBy(AerospikeReference.ReferenceType type) { - this.binConfig.setReference(new ReferenceConfig(type, false)); + this.binConfig.setReference(new ReferenceConfig(type, false, true)); return this.end(); } public Builder beingLazilyReferencedBy(AerospikeReference.ReferenceType type) { - this.binConfig.setReference(new ReferenceConfig(type, true)); + this.binConfig.setReference(new ReferenceConfig(type, true, true)); return this.end(); } diff --git a/src/main/java/com/aerospike/mapper/tools/configuration/ReferenceConfig.java b/src/main/java/com/aerospike/mapper/tools/configuration/ReferenceConfig.java index ddf6c03..39cc510 100644 --- a/src/main/java/com/aerospike/mapper/tools/configuration/ReferenceConfig.java +++ b/src/main/java/com/aerospike/mapper/tools/configuration/ReferenceConfig.java @@ -8,9 +8,10 @@ public class ReferenceConfig { private Boolean batchLoad; public ReferenceConfig() {} - public ReferenceConfig(ReferenceType type, boolean lazy) { + public ReferenceConfig(ReferenceType type, boolean lazy, boolean batchLoad) { this.type = type; this.lazy = lazy; + this.batchLoad = batchLoad; } public ReferenceType getType() { diff --git a/src/main/java/com/aerospike/mapper/tools/utils/TypeUtils.java b/src/main/java/com/aerospike/mapper/tools/utils/TypeUtils.java index 4592c32..02d740e 100644 --- a/src/main/java/com/aerospike/mapper/tools/utils/TypeUtils.java +++ b/src/main/java/com/aerospike/mapper/tools/utils/TypeUtils.java @@ -229,7 +229,11 @@ private static TypeMapper getMapper(Class clazz, AnnotatedType type, IBaseAer } else { // Reference ReferenceConfig ref = binConfig.getReference(); - typeMapper = new ObjectReferenceMapper(ClassCache.getInstance().loadClass(clazz, mapper), ref.getLazy(), ref.getBatchLoad(), ref.getType(), mapper); + typeMapper = new ObjectReferenceMapper( + ClassCache.getInstance().loadClass(clazz, mapper), + ref.getLazy() == null? false : ref.getLazy(), + ref.getBatchLoad() == null ? true : ref.getBatchLoad(), + ref.getType(), mapper); addToMap = false; } } else {