From e53e829f78f4af52f40fe83e1dbeed0b524a6801 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Thu, 28 Dec 2023 01:37:24 -0700 Subject: [PATCH] handle null return from func.apply --- build.gradle | 2 +- .../database/tables/table/DataTable.java | 26 +++++++++++++------ .../library/helpers/models/AuthorDE.java | 2 -- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 58dd736..93b4f9d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.nucleodb' -version = '1.13.21' +version = '1.13.22' repositories { mavenCentral() diff --git a/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java b/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java index 566dc35..2f2a8c3 100644 --- a/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java +++ b/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java @@ -8,6 +8,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Queues; +import com.google.common.collect.Sets; import com.nucleodb.library.database.modifications.ConnectionCreate; import com.nucleodb.library.database.modifications.ConnectionDelete; import com.nucleodb.library.database.modifications.ConnectionUpdate; @@ -281,22 +282,31 @@ public Set handleIndexOperation(Object obj, DataEntryProjection dataE if (dataEntryProjection == null) { dataEntryProjection = new DataEntryProjection(); } - Stream process = dataEntryProjection.process(func.apply(obj).stream()); - if (dataEntryProjection.isWritable()) { - return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet()); + Set apply = func.apply(obj); + if(apply!=null) { + Stream process = dataEntryProjection.process(apply.stream()); + + if (dataEntryProjection.isWritable()) { + return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet()); + } + return process.collect(Collectors.toSet()); } - return process.collect(Collectors.toSet()); + return Sets.newTreeSet(); } public Set handleIndexStringOperation(String obj, DataEntryProjection dataEntryProjection, Function> func) { if (dataEntryProjection == null) { dataEntryProjection = new DataEntryProjection(); } - Stream process = dataEntryProjection.process(func.apply(obj).stream()); - if (dataEntryProjection.isWritable()) { - return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet()); + Set apply = func.apply(obj); + if(apply!=null) { + Stream process = dataEntryProjection.process(apply.stream()); + if (dataEntryProjection.isWritable()) { + return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet()); + } + return process.collect(Collectors.toSet()); } - return process.collect(Collectors.toSet()); + return Sets.newTreeSet(); } public Set search(String key, Object searchObject, DataEntryProjection dataEntryProjection) { diff --git a/src/test/java/com/nucleodb/library/helpers/models/AuthorDE.java b/src/test/java/com/nucleodb/library/helpers/models/AuthorDE.java index 9904c2f..9188a10 100644 --- a/src/test/java/com/nucleodb/library/helpers/models/AuthorDE.java +++ b/src/test/java/com/nucleodb/library/helpers/models/AuthorDE.java @@ -4,8 +4,6 @@ import com.nucleodb.library.database.modifications.Create; import com.nucleodb.library.database.tables.table.DataEntry; -import java.util.UUID; - public class AuthorDE extends DataEntry{ public AuthorDE(Author obj) { super(obj);