Skip to content

Commit e2f3482

Browse files
committed
Split the controls to avoid NPE
1 parent b433672 commit e2f3482

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/tables/Table.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,17 @@ public <R> Optional<R> findOne(Filter filter, TableFindOneOptions findOneOptions
604604

605605
DataAPIData data = runCommand(findOne, findOneOptions).getData();
606606

607-
return Optional
608-
.ofNullable(data.getDocument()
609-
.map(Row.class))
610-
.map(row -> RowMapper.mapFromRow(row, getSerializer(), newRowClass));
607+
// No data found
608+
if (data == null || data.getDocument() == null) {
609+
return Optional.empty();
610+
}
611+
612+
// Document -> Row
613+
Row row = new Row();
614+
row.getColumnMap().putAll(data.getDocument().getDocumentMap());
615+
616+
// Row -> Optional<T>
617+
return Optional.ofNullable(RowMapper.mapFromRow(row, getSerializer(), newRowClass));
611618
}
612619

613620
/**

astra-db-java/src/main/java/com/datastax/astra/internal/command/ExecutionInfos.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ public ExecutionInfos build() {
269269

270270
/**
271271
* Execute the command and populate the response.
272+
* @return
273+
* the response
272274
*/
273275
public long getExecutionTime() {
274276
return executionTime;

0 commit comments

Comments
 (0)