Skip to content

Commit

Permalink
NPE using refs with the YAML file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tim-aero committed Jun 14, 2024
1 parent 4533700 commit 2fed6db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2fed6db

Please sign in to comment.