Skip to content

Commit 4063fce

Browse files
authored
Fixed NPE warnings (#127)
2 parents 52c769a + 7788229 commit 4063fce

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

jdbc/src/main/java/tech/ydb/jdbc/context/YdbContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,10 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
429429
}
430430

431431
QueryType type = query.getType();
432+
YqlBatcher batcher = query.getYqlBatcher();
432433

433434
if (type == QueryType.BULK_QUERY) {
434-
if (query.getYqlBatcher() == null || query.getYqlBatcher().getCommand() != YqlBatcher.Cmd.UPSERT) {
435+
if (batcher == null || batcher.getCommand() != YqlBatcher.Cmd.UPSERT) {
435436
throw new SQLException(YdbConst.BULKS_UNSUPPORTED);
436437
}
437438
}
@@ -441,8 +442,8 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
441442
return new InMemoryQuery(query, queryOptions.isDeclareJdbcParameters());
442443
}
443444

444-
if (query.getYqlBatcher() != null && (mode == YdbPrepareMode.AUTO || type == QueryType.BULK_QUERY)) {
445-
String tablePath = joined(getPrefixPath(), query.getYqlBatcher().getTableName());
445+
if (batcher != null && (mode == YdbPrepareMode.AUTO || type == QueryType.BULK_QUERY)) {
446+
String tablePath = joined(getPrefixPath(), batcher.getTableName());
446447
TableDescription description = tableDescribeCache.getIfPresent(tablePath);
447448
if (description == null) {
448449
YdbTracer tracer = getTracer();
@@ -469,7 +470,7 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
469470
if (query.getReturning() != null) {
470471
throw new SQLException(YdbConst.BULK_NOT_SUPPORT_RETURNING);
471472
}
472-
return BulkUpsertQuery.build(types, tablePath, query.getYqlBatcher().getColumns(), description);
473+
return BulkUpsertQuery.build(types, tablePath, batcher.getColumns(), description);
473474
}
474475

475476
if (description != null) {

jdbc/src/main/java/tech/ydb/jdbc/impl/BaseYdbResultSet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private ValueReader readValue(int columnIndex) throws SQLException {
9393

9494
ValueReader value = getValue(columnIndex - 1);
9595
ColumnInfo type = columns[columnIndex - 1];
96-
wasNull = type.isNull() || (type.isOptional() && !value.isOptionalItemPresent());
96+
wasNull = type == null || type.isNull() || (type.isOptional() && !value.isOptionalItemPresent());
9797
return value;
9898
}
9999

@@ -594,10 +594,10 @@ public Value<?> getNativeColumn(int columnIndex) throws SQLException {
594594
if (wasNull) {
595595
return null;
596596
}
597-
while (value.getType().getKind() == Type.Kind.OPTIONAL) {
597+
while (value != null && value.getType().getKind() == Type.Kind.OPTIONAL) {
598598
value = value.getOptionalItem();
599599
}
600-
return value.getValue();
600+
return value == null ? null : value.getValue();
601601
}
602602

603603
@Override

jdbc/src/main/java/tech/ydb/jdbc/query/params/BatchedQuery.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ public static BatchedQuery createAutoBatched(YdbTypes types, YdbQuery query, Tab
234234
throws SQLException {
235235

236236
YqlBatcher batcher = query.getYqlBatcher();
237+
if (batcher == null) {
238+
return null;
239+
}
237240

238241
// DELETE and UPDATE may be batched only if WHERE contains only primary key columns
239242
if (batcher.getCommand() == YqlBatcher.Cmd.DELETE || batcher.getCommand() == YqlBatcher.Cmd.UPDATE) {

0 commit comments

Comments
 (0)