diff --git a/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/BaseFlightReader.java b/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/BaseFlightReader.java index b30f561fda..f974cdfa6e 100644 --- a/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/BaseFlightReader.java +++ b/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/BaseFlightReader.java @@ -37,7 +37,7 @@ import org.apache.arrow.vector.ipc.ArrowReader; import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; import org.apache.arrow.vector.types.pojo.Schema; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** Base class for ArrowReaders based on consuming data from FlightEndpoints. */ public abstract class BaseFlightReader extends ArrowReader { @@ -45,8 +45,8 @@ public abstract class BaseFlightReader extends ArrowReader { private final List flightEndpoints; private final Supplier> rpcCall; private int nextEndpointIndex = 0; - private @MonotonicNonNull FlightStream currentStream = null; - private @MonotonicNonNull Schema schema = null; + private @Nullable FlightStream currentStream = null; + private @Nullable Schema schema = null; private long bytesRead = 0; protected final FlightSqlClientWithCallOptions client; protected final LoadingCache clientCache; @@ -65,7 +65,7 @@ protected BaseFlightReader( @Override public boolean loadNextBatch() throws IOException { - Preconditions.checkNotNull(currentStream); + Preconditions.checkState(currentStream != null); if (!currentStream.next()) { if (nextEndpointIndex >= flightEndpoints.size()) { return false; @@ -94,7 +94,7 @@ public boolean loadNextBatch() throws IOException { @Override protected Schema readSchema() throws IOException { - Preconditions.checkNotNull(currentStream); + Preconditions.checkState(schema != null); return schema; } diff --git a/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/GetInfoMetadataReader.java b/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/GetInfoMetadataReader.java index 16581080ae..3dffc1268e 100644 --- a/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/GetInfoMetadataReader.java +++ b/java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/GetInfoMetadataReader.java @@ -40,7 +40,6 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.DenseUnionVector; import org.apache.arrow.vector.types.pojo.Schema; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** Helper class to track state needed to build up the info structure. */ @@ -51,12 +50,12 @@ final class GetInfoMetadataReader extends BaseFlightReader { private final BufferAllocator allocator; private final Collection requestedCodes; - private @MonotonicNonNull UInt4Vector infoCodes = null; - private @MonotonicNonNull DenseUnionVector infoValues = null; - private @MonotonicNonNull VarCharVector stringValues = null; + private @Nullable UInt4Vector infoCodes = null; + private @Nullable DenseUnionVector infoValues = null; + private @Nullable VarCharVector stringValues = null; private boolean hasInMemoryDataBeenWritten = false; - private boolean hasInMemoryData; - private boolean hasSupportedCodes; + private final boolean hasInMemoryData; + private final boolean hasSupportedCodes; private boolean hasRequestBeenIssued = false; @FunctionalInterface @@ -75,14 +74,14 @@ void accept( SUPPORTED_CODES.put( FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME.getNumber(), (b, sqlInfo, srcIndex, dstIndex) -> { - Preconditions.checkNotNull(b.infoCodes); + Preconditions.checkState(b.infoCodes != null); b.infoCodes.setSafe(dstIndex, AdbcInfoCode.VENDOR_NAME.getValue()); b.setStringValue(dstIndex, sqlInfo.getVarCharVector(STRING_VALUE_TYPE_ID).get(srcIndex)); }); SUPPORTED_CODES.put( FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION.getNumber(), (b, sqlInfo, srcIndex, dstIndex) -> { - Preconditions.checkNotNull(b.infoCodes); + Preconditions.checkState(b.infoCodes != null); b.infoCodes.setSafe(dstIndex, AdbcInfoCode.VENDOR_VERSION.getValue()); b.setStringValue(dstIndex, sqlInfo.getVarCharVector(STRING_VALUE_TYPE_ID).get(srcIndex)); }); @@ -120,16 +119,18 @@ static GetInfoMetadataReader CreateGetInfoMetadataReader( this.hasInMemoryData = requestedCodes.contains(AdbcInfoCode.DRIVER_NAME.getValue()) || requestedCodes.contains(AdbcInfoCode.DRIVER_VERSION.getValue()); + boolean hasRequestedCode = false; for (Integer requestedCode : requestedCodes) { if (SUPPORTED_CODES.containsKey(requestedCode)) { - hasSupportedCodes = true; + hasRequestedCode = true; break; } } + hasSupportedCodes = hasRequestedCode; } void setStringValue(int index, byte[] value) { - Preconditions.checkNotNull(infoValues, stringValues); + Preconditions.checkState(infoValues != null && stringValues != null); infoValues.setValueCount(index + 1); infoValues.setTypeId(index, STRING_VALUE_TYPE_ID); stringValues.setSafe(index, value);