This is an automated email from the ASF dual-hosted git repository.

FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 85c5892d729 fix: address CodeQL nullness and type warnings (#19823)
85c5892d729 is described below

commit 85c5892d729cad26a584390b8673a40ad5aa659c
Author: Frank Chen <[email protected]>
AuthorDate: Wed Sep 30 15:16:19 2026 +0800

    fix: address CodeQL nullness and type warnings (#19823)
    
    * Fix CodeQL nullness and type warnings
    
    * fix: address nullness review feedback
    
    * fix: address suppressed nullness review findings
    
    * test: migrate nullness tests to JUnit 5
    
    * fix: remove unused import
---
 .../apache/druid/delta/input/DeltaInputSource.java |  3 +-
 .../emitter/prometheus/PrometheusEmitter.java      |  4 +-
 .../histogram/ApproximateHistogram.java            |  2 +
 .../indexing/kafka/supervisor/KafkaSupervisor.java |  2 +-
 ...ashPartitionMultiPhaseParallelIndexingTest.java |  5 +-
 .../indexing/overlord/TaskQueueScaleTest.java      |  6 ++-
 .../org/apache/druid/hll/HyperLogLogCollector.java | 21 ++++----
 .../jackson/DruidDefaultSerializersModule.java     |  5 +-
 .../druid/java/util/common/logger/Logger.java      |  2 +-
 .../java/org/apache/druid/math/expr/Function.java  | 10 ++--
 .../rowsandcols/LazilyDecoratedRowsAndColumns.java | 62 ++++++++++------------
 .../segment/generator/ColumnValueGenerator.java    | 15 +++++-
 .../common/parsers/JSONFlattenerMakerTest.java     |  4 +-
 .../first/StringFirstBufferAggregatorTest.java     |  8 +--
 .../last/StringLastBufferAggregatorTest.java       |  8 +--
 .../segment/data/BenchmarkIndexibleWrites.java     | 11 ++--
 .../filter/PredicateValueMatcherFactoryTest.java   | 16 +++---
 .../druid/segment/generator/DataGeneratorTest.java | 21 ++++++++
 .../join/table/IndexedTableJoinMatcherTest.java    | 10 ++--
 .../org/apache/druid/utils/CloseableUtilsTest.java | 14 ++---
 .../segment/loading/SegmentLocalCacheManager.java  |  6 +--
 .../org/apache/druid/rpc/MockServiceClient.java    |  8 ++-
 .../utils/ImmutableDruidDataSourceTestUtils.java   | 11 ++--
 .../ImmutableDruidDataSourceTestUtilsTest.java     | 46 ++++++++++++++++
 .../builtin/EarliestLatestAnySqlAggregator.java    | 14 ++---
 25 files changed, 200 insertions(+), 114 deletions(-)

diff --git 
a/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java
 
b/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java
index 44dc34ca3d2..be7b0f479e0 100644
--- 
a/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java
+++ 
b/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java
@@ -62,6 +62,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -161,7 +162,7 @@ public class DeltaInputSource implements 
SplittableInputSource<DeltaSplit>
         final StructType fullSnapshotSchema = snapshot.getSchema();
         final StructType prunedSchema = pruneSchema(
             fullSnapshotSchema,
-            inputRowSchema.getColumnsFilter()
+            Objects.requireNonNull(inputRowSchema, 
"inputRowSchema").getColumnsFilter()
         );
 
         final ScanBuilder scanBuilder = snapshot.getScanBuilder();
diff --git 
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
 
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
index 60af27fcd4d..e73fdfcf444 100644
--- 
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
+++ 
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
@@ -236,7 +236,9 @@ public class PrometheusEmitter implements Emitter
         server.close();
       }
     } else {
-      exec.shutdownNow();
+      if (exec != null) {
+        exec.shutdownNow();
+      }
       flush();
 
       try {
diff --git 
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java
 
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java
index 8f72d3046ee..5cf7f75832b 100644
--- 
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java
+++ 
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java
@@ -626,6 +626,8 @@ public class ApproximateHistogram
     // use preallocated arrays if passed
     if (mergedPositions == null) {
       mergedPositions = new float[this.size];
+    }
+    if (mergedBins == null) {
       mergedBins = new long[this.size];
     }
 
diff --git 
a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
 
b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
index 0d8fa70f7f1..c658f45c45c 100644
--- 
a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
+++ 
b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
@@ -145,7 +145,7 @@ public class KafkaSupervisor extends 
SeekableStreamSupervisor<KafkaTopicPartitio
   @Override
   protected int getTaskGroupIdForPartition(KafkaTopicPartition partitionId)
   {
-    Integer taskCount = spec.getIoConfig().getTaskCount();
+    final int taskCount = spec.getIoConfig().getTaskCount();
     if (partitionId.isMultiTopicPartition()) {
       return Math.abs(31 * partitionId.topic().hashCode() + 
partitionId.partition()) % taskCount;
     } else {
diff --git 
a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java
 
b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java
index f45a950175e..e92d3500edc 100644
--- 
a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java
+++ 
b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java
@@ -352,18 +352,17 @@ public class HashPartitionMultiPhaseParallelIndexingTest 
extends AbstractMultiPh
       List<DataSegment> segmentsInInterval = entry.getValue();
       
Assertions.assertEquals(expectedIntervalToNumSegments.get(interval).intValue(), 
segmentsInInterval.size());
       for (DataSegment segment : segmentsInInterval) {
-        HashBasedNumberedShardSpec shardSpec = null;
         if (segment.isTombstone()) {
           Assertions.assertSame(TombstoneShardSpec.class, 
segment.getShardSpec().getClass());
         } else {
           Assertions.assertSame(HashBasedNumberedShardSpec.class, 
segment.getShardSpec().getClass());
-          shardSpec = (HashBasedNumberedShardSpec) segment.getShardSpec();
-          Assertions.assertEquals(HashPartitionFunction.MURMUR3_32_ABS, 
shardSpec.getPartitionFunction());
         }
         List<ScanResultValue> results = querySegment(segment, 
ImmutableList.of("dim1", "dim2"), tempSegmentDir);
         if (segment.isTombstone()) {
           Assertions.assertTrue(results.isEmpty());
         } else {
+          final HashBasedNumberedShardSpec shardSpec = 
(HashBasedNumberedShardSpec) segment.getShardSpec();
+          Assertions.assertEquals(HashPartitionFunction.MURMUR3_32_ABS, 
shardSpec.getPartitionFunction());
           final int hash = shardSpec.getPartitionFunction().hash(
               HashBasedNumberedShardSpec.serializeGroupKey(
                   getObjectMapper(),
diff --git 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java
 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java
index e0c21df78b3..6d2e556f7c4 100644
--- 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java
+++ 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java
@@ -283,7 +283,7 @@ public class TaskQueueScaleTest
               try {
                 synchronized (knownTasks) {
                   final TestTaskRunnerWorkItem item2 = 
knownTasks.get(task.getId());
-                  if (item2.getState() == RunnerTaskState.PENDING) {
+                  if (item2 != null && item2.getState() == 
RunnerTaskState.PENDING) {
                     knownTasks.put(task.getId(), 
item2.withState(RunnerTaskState.RUNNING));
                   }
                 }
@@ -294,7 +294,9 @@ public class TaskQueueScaleTest
                         final TestTaskRunnerWorkItem item2;
                         synchronized (knownTasks) {
                           item2 = knownTasks.get(task.getId());
-                          knownTasks.put(task.getId(), 
item2.withState(RunnerTaskState.NONE));
+                          if (item2 != null) {
+                            knownTasks.put(task.getId(), 
item2.withState(RunnerTaskState.NONE));
+                          }
                         }
                         if (item2 != null) {
                           item2.setResult(TaskStatus.success(task.getId()));
diff --git 
a/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java 
b/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java
index 2e0460a5649..efc283ff155 100644
--- a/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java
+++ b/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java
@@ -582,32 +582,31 @@ public abstract class HyperLogLogCollector implements 
Comparable<HyperLogLogColl
       return false;
     }
 
-    ByteBuffer otherBuffer = ((HyperLogLogCollector) o).storageBuffer;
+    final ByteBuffer otherBuffer = ((HyperLogLogCollector) o).storageBuffer;
 
-    if (storageBuffer != null ? false : otherBuffer != null) {
-      return false;
-    }
-
-    if (storageBuffer == null && otherBuffer == null) {
-      return true;
+    if (storageBuffer == null || otherBuffer == null) {
+      return storageBuffer == otherBuffer;
     }
 
     final ByteBuffer denseStorageBuffer;
     if (storageBuffer.remaining() != getNumBytesForDenseStorage()) {
-      HyperLogLogCollector denseCollector = 
HyperLogLogCollector.makeCollector(storageBuffer.duplicate());
+      final HyperLogLogCollector denseCollector = 
HyperLogLogCollector.makeCollector(storageBuffer.duplicate());
       denseCollector.convertToDenseStorage();
       denseStorageBuffer = denseCollector.storageBuffer;
     } else {
       denseStorageBuffer = storageBuffer;
     }
 
+    final ByteBuffer denseOtherBuffer;
     if (otherBuffer.remaining() != getNumBytesForDenseStorage()) {
-      HyperLogLogCollector otherCollector = 
HyperLogLogCollector.makeCollector(otherBuffer.duplicate());
+      final HyperLogLogCollector otherCollector = 
HyperLogLogCollector.makeCollector(otherBuffer.duplicate());
       otherCollector.convertToDenseStorage();
-      otherBuffer = otherCollector.storageBuffer;
+      denseOtherBuffer = otherCollector.storageBuffer;
+    } else {
+      denseOtherBuffer = otherBuffer;
     }
 
-    return denseStorageBuffer.equals(otherBuffer);
+    return denseStorageBuffer.equals(denseOtherBuffer);
   }
 
   @Override
diff --git 
a/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java
 
b/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java
index da78a0a7461..65489c3db09 100644
--- 
a/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java
+++ 
b/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java
@@ -40,6 +40,7 @@ import org.joda.time.DateTimeZone;
 
 import java.io.IOException;
 import java.nio.ByteOrder;
+import java.util.Objects;
 
 /**
  *
@@ -152,8 +153,8 @@ public class DruidDefaultSerializersModule extends 
SimpleModule
                 } else {
                   final Class<?> clazz = o.getClass();
 
-                  if (serializerClass != clazz) {
-                    serializer = JacksonUtils.getSerializer(provider, clazz);
+                  if (serializer == null || serializerClass != clazz) {
+                    serializer = 
Objects.requireNonNull(JacksonUtils.getSerializer(provider, clazz));
                     serializerClass = clazz;
                   }
 
diff --git 
a/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java 
b/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java
index 1c1285c8b0c..c9221d5a357 100644
--- 
a/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java
+++ 
b/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java
@@ -295,7 +295,7 @@ public class Logger
 
       fn.accept(message, t);
     } else {
-      if (message.isEmpty()) {
+      if (message == null || message.isEmpty()) {
         fn.accept(t.toString(), null);
       } else {
         fn.accept(StringUtils.nonStrictFormat("%s (%s)", message, 
t.toString()), null);
diff --git a/processing/src/main/java/org/apache/druid/math/expr/Function.java 
b/processing/src/main/java/org/apache/druid/math/expr/Function.java
index c43e8642f9a..d2d9995d9c9 100644
--- a/processing/src/main/java/org/apache/druid/math/expr/Function.java
+++ b/processing/src/main/java/org/apache/druid/math/expr/Function.java
@@ -3268,13 +3268,15 @@ public interface Function extends NamedFunction
     @Override
     public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
     {
-      Long left = args.get(0).eval(bindings).asLong();
-      Long right = args.get(1).eval(bindings).asLong();
-      DateTimeZone timeZone = 
DateTimes.inferTzFromString(args.get(2).eval(bindings).asString());
+      final ExprEval<?> leftEval = args.get(0).eval(bindings);
+      final ExprEval<?> rightEval = args.get(1).eval(bindings);
+      final DateTimeZone timeZone = 
DateTimes.inferTzFromString(args.get(2).eval(bindings).asString());
 
-      if (left == null || right == null) {
+      if (leftEval.isNumericNull() || rightEval.isNumericNull()) {
         return ExprEval.ofLong(null);
       } else {
+        final long left = leftEval.asLong();
+        final long right = rightEval.asLong();
         return ExprEval.of(DateTimes.subMonths(right, left, timeZone));
       }
 
diff --git 
a/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java
 
b/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java
index a45c999b3c8..270ab566814 100644
--- 
a/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java
+++ 
b/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java
@@ -276,21 +276,15 @@ public class LazilyDecoratedRowsAndColumns implements 
RowsAndColumns
           sortColumns
       );
 
-      final FrameWriter writer = 
frameWriterFactory.newFrameWriter(columnSelectorFactory);
-      for (; !cursor.isDoneOrInterrupted() && remainingRowsToSkip > 0; 
remainingRowsToSkip--) {
-        cursor.advance();
-      }
-      for (; !cursor.isDoneOrInterrupted() && remainingRowsToFetch > 0; 
remainingRowsToFetch--) {
-        writer.addSelection();
-        cursor.advance();
-      }
+      try (final FrameWriter writer = 
frameWriterFactory.newFrameWriter(columnSelectorFactory)) {
+        for (; !cursor.isDoneOrInterrupted() && remainingRowsToSkip > 0; 
remainingRowsToSkip--) {
+          cursor.advance();
+        }
+        for (; !cursor.isDoneOrInterrupted() && remainingRowsToFetch > 0; 
remainingRowsToFetch--) {
+          writer.addSelection();
+          cursor.advance();
+        }
 
-      if (writer == null) {
-        // This means that the accumulate was never called, which can only 
happen if we didn't have any cursors.
-        // We would only have zero cursors if we essentially didn't match 
anything, meaning that our RowsAndColumns
-        // should be completely empty.
-        return null;
-      } else {
         final byte[] bytes = writer.toByteArray();
         return Pair.of(bytes, siggy.get());
       }
@@ -383,26 +377,28 @@ public class LazilyDecoratedRowsAndColumns implements 
RowsAndColumns
     long remainingRowsToSkip = limit.getOffset();
     long remainingRowsToFetch = limit.getLimitOrMax();
 
-    final FrameWriter frameWriter = 
FrameWriters.makeColumnBasedFrameWriterFactory(
-        memFactory,
-        sigBob.build(),
-        Collections.emptyList()
-    ).newFrameWriter(selectorFactory);
-
-    rowId.set(0);
-    for (; rowId.get() < numRows && remainingRowsToFetch > 0; 
rowId.incrementAndGet()) {
-      final int theId = rowId.get();
-      if (rowsToSkip != null && rowsToSkip.get(theId)) {
-        continue;
-      }
-      if (remainingRowsToSkip > 0) {
-        remainingRowsToSkip--;
-        continue;
+    try (
+        final FrameWriter frameWriter = 
FrameWriters.makeColumnBasedFrameWriterFactory(
+            memFactory,
+            sigBob.build(),
+            Collections.emptyList()
+        ).newFrameWriter(selectorFactory)
+    ) {
+      rowId.set(0);
+      for (; rowId.get() < numRows && remainingRowsToFetch > 0; 
rowId.incrementAndGet()) {
+        final int theId = rowId.get();
+        if (rowsToSkip != null && rowsToSkip.get(theId)) {
+          continue;
+        }
+        if (remainingRowsToSkip > 0) {
+          remainingRowsToSkip--;
+          continue;
+        }
+        remainingRowsToFetch--;
+        frameWriter.addSelection();
       }
-      remainingRowsToFetch--;
-      frameWriter.addSelection();
-    }
 
-    return Pair.of(frameWriter.toByteArray(), sigBob.build());
+      return Pair.of(frameWriter.toByteArray(), sigBob.build());
+    }
   }
 }
diff --git 
a/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java
 
b/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java
index 1fc09f57be6..b4c4e83bbea 100644
--- 
a/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java
+++ 
b/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java
@@ -19,6 +19,7 @@
 
 package org.apache.druid.segment.generator;
 
+import com.google.common.base.Preconditions;
 import org.apache.commons.math3.distribution.AbstractIntegerDistribution;
 import org.apache.commons.math3.distribution.AbstractRealDistribution;
 import org.apache.commons.math3.distribution.EnumeratedDistribution;
@@ -207,8 +208,18 @@ public class ColumnValueGenerator implements 
Supplier<Object>
         distribution = new UniformIntegerDistribution(schema.getStartInt(), 
schema.getEndInt());
         break;
       case ENUMERATED:
-        for (int i = 0; i < enumeratedValues.size(); i++) {
-          probabilities.add(new Pair<>(enumeratedValues.get(i), 
enumeratedProbabilities.get(i)));
+        final List<Object> nonNullEnumeratedValues =
+            Preconditions.checkNotNull(enumeratedValues, "enumeratedValues");
+        final List<Double> nonNullEnumeratedProbabilities =
+            Preconditions.checkNotNull(enumeratedProbabilities, 
"enumeratedProbabilities");
+        Preconditions.checkArgument(
+            nonNullEnumeratedValues.size() == 
nonNullEnumeratedProbabilities.size(),
+            "enumeratedValues size[%s] must match enumeratedProbabilities 
size[%s]",
+            nonNullEnumeratedValues.size(),
+            nonNullEnumeratedProbabilities.size()
+        );
+        for (int i = 0; i < nonNullEnumeratedValues.size(); i++) {
+          probabilities.add(new Pair<>(nonNullEnumeratedValues.get(i), 
nonNullEnumeratedProbabilities.get(i)));
         }
         distribution = new EnumeratedTreeDistribution<>(probabilities);
         break;
diff --git 
a/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java
 
b/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java
index 6f1d87a8c35..13b4b2b63a4 100644
--- 
a/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java
+++ 
b/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java
@@ -67,11 +67,11 @@ public class JSONFlattenerMakerTest
   {
     JsonNode node;
     Object result;
-    Integer i1 = 123;
+    final int i1 = 123;
     node = OBJECT_MAPPER.readTree(OBJECT_MAPPER.writeValueAsString(i1));
     Assertions.assertTrue(node.isInt());
     result = FLATTENER_MAKER.finalizeConversionForMap(node);
-    Assertions.assertEquals(i1.longValue(), result);
+    Assertions.assertEquals((long) i1, result);
 
     Long l1 = 1L + Integer.MAX_VALUE;
     node = OBJECT_MAPPER.readTree(OBJECT_MAPPER.writeValueAsString(l1));
diff --git 
a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java
 
b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java
index 581707b4be0..a5d83f6a0a1 100644
--- 
a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java
+++ 
b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java
@@ -48,7 +48,7 @@ public class StringFirstBufferAggregatorTest
   {
     final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 
1526725900L, 1526725000L};
     final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -85,7 +85,7 @@ public class StringFirstBufferAggregatorTest
   {
     final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 
1526725900L, 1526725000L};
     final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -123,7 +123,7 @@ public class StringFirstBufferAggregatorTest
 
     final long[] timestamps = {2222L, 1111L, 3333L, 4444L, 5555L};
     final String[] strings = {null, "AAAA", "BBBB", "DDDD", "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -162,7 +162,7 @@ public class StringFirstBufferAggregatorTest
 
     final long[] timestamps = {1526724000L, 1526724600L};
     final Double[] doubles = {null, 2.00};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<Double> objectColumnSelector = new 
TestObjectColumnSelector<>(doubles);
diff --git 
a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java
 
b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java
index 3f1e66f802a..5f38c623982 100644
--- 
a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java
+++ 
b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java
@@ -49,7 +49,7 @@ public class StringLastBufferAggregatorTest
 
     final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 
1526725900L, 1526725000L};
     final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -87,7 +87,7 @@ public class StringLastBufferAggregatorTest
   {
     final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 
1526725900L, 1526725000L};
     final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -125,7 +125,7 @@ public class StringLastBufferAggregatorTest
 
     final long[] timestamps = {1111L, 2222L, 6666L, 4444L, 5555L};
     final String[] strings = {"CCCC", "AAAA", "BBBB", null, "EEEE"};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<String> objectColumnSelector = new 
TestObjectColumnSelector<>(strings);
@@ -164,7 +164,7 @@ public class StringLastBufferAggregatorTest
 
     final long[] timestamps = {1526724000L, 1526724600L};
     final Double[] doubles = {null, 2.00};
-    Integer maxStringBytes = 1024;
+    final int maxStringBytes = 1024;
 
     TestLongColumnSelector longColumnSelector = new 
TestLongColumnSelector(timestamps);
     TestObjectColumnSelector<Double> objectColumnSelector = new 
TestObjectColumnSelector<>(doubles);
diff --git 
a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java
 
b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java
index a92dfcb6183..e718f07c781 100644
--- 
a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java
+++ 
b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java
@@ -128,7 +128,7 @@ public class BenchmarkIndexibleWrites
       reference.set((V[]) new Object[initSize]);
     }
 
-    private static Boolean wasCopying(Long val)
+    private static boolean wasCopying(long val)
     {
       return (val & 1L) > 0;
     }
@@ -137,12 +137,13 @@ public class BenchmarkIndexibleWrites
     public void set(Integer index, V object)
     {
       ensureCapacity(index + 1);
-      Long pre, post;
+      long pre;
+      long post;
       do {
         pre = resizeCount.get();
         reference.get()[index] = object;
         post = resizeCount.get();
-      } while (wasCopying(pre) || wasCopying(post) || (!pre.equals(post)));
+      } while (wasCopying(pre) || wasCopying(post) || pre != post);
     }
 
     private final Object resizeMutex = new Object();
@@ -192,7 +193,7 @@ public class BenchmarkIndexibleWrites
     final AtomicInteger index = new AtomicInteger(0);
     List<ListenableFuture<?>> futures = new ArrayList<>();
 
-    final Integer loops = totalIndexSize / concurrentThreads;
+    final int loops = totalIndexSize / concurrentThreads;
 
     for (int i = 0; i < concurrentThreads; ++i) {
       futures.add(
@@ -244,7 +245,7 @@ public class BenchmarkIndexibleWrites
     final AtomicInteger queryableIndex = new AtomicInteger(0);
     List<ListenableFuture<?>> futures = new ArrayList<>();
 
-    final Integer loops = totalIndexSize / concurrentThreads;
+    final int loops = totalIndexSize / concurrentThreads;
 
     final AtomicBoolean done = new AtomicBoolean(false);
 
diff --git 
a/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java
 
b/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java
index 58c49b31887..1a440f9a3bb 100644
--- 
a/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java
+++ 
b/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java
@@ -158,26 +158,26 @@ public class PredicateValueMatcherFactoryTest extends 
InitializedNullHandlingTes
   @Test
   public void testNumberProcessorMatchingValue()
   {
-    Double num = 2.;
+    final double num = 2.;
     final TestColumnValueSelector<Number> columnValueSelector = 
TestColumnValueSelector.of(
             Number.class,
             ImmutableList.of(new Number() {
               @Override
               public int intValue()
               {
-                return num.intValue();
+                return (int) num;
               }
 
               @Override
               public long longValue()
               {
-                return num.longValue();
+                return (long) num;
               }
 
               @Override
               public float floatValue()
               {
-                return num.floatValue();
+                return (float) num;
               }
 
               @Override
@@ -195,26 +195,26 @@ public class PredicateValueMatcherFactoryTest extends 
InitializedNullHandlingTes
   @Test
   public void testNumberProcessorNotMatchingValue()
   {
-    Double num = 2.;
+    final double num = 2.;
     final TestColumnValueSelector<Double> columnValueSelector = 
TestColumnValueSelector.of(
             Double.class,
             ImmutableList.of(new Number() {
               @Override
               public int intValue()
               {
-                return num.intValue();
+                return (int) num;
               }
 
               @Override
               public long longValue()
               {
-                return num.longValue();
+                return (long) num;
               }
 
               @Override
               public float floatValue()
               {
-                return num.floatValue();
+                return (float) num;
               }
 
               @Override
diff --git 
a/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java
 
b/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java
index 0a4e490af3b..973fbe4e1a3 100644
--- 
a/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java
+++ 
b/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java
@@ -298,6 +298,27 @@ public class DataGeneratorTest extends 
InitializedNullHandlingTest
     tracker.assertTotalRowSize("dimA", 10000);
   }
 
+  @Test
+  public void testEnumeratedRejectsMismatchedValuesAndProbabilities()
+  {
+    final GeneratorColumnSchema schema = GeneratorColumnSchema.makeEnumerated(
+        "dimA",
+        ValueType.STRING,
+        false,
+        1,
+        null,
+        Arrays.asList("Hello", "World"),
+        Collections.singletonList(1.0)
+    );
+
+    final IllegalArgumentException exception = Assertions.assertThrows(
+        IllegalArgumentException.class,
+        () -> schema.makeGenerator(9999)
+    );
+    Assertions.assertTrue(exception.getMessage().contains("enumeratedValues 
size[2]"));
+    
Assertions.assertTrue(exception.getMessage().contains("enumeratedProbabilities 
size[1]"));
+  }
+
   @Test
   public void testNormal()
   {
diff --git 
a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
 
b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
index 26a45eaae25..259450f6947 100644
--- 
a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
+++ 
b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
@@ -371,15 +371,15 @@ public class IndexedTableJoinMatcherTest
     @Test
     public void evictsLeastRecentlyUsed()
     {
-      Long start = 1L;
-      Long next = start + SIZE;
+      final long start = 1L;
+      final long next = start + SIZE;
 
       for (long i = start; i < next; i++) {
-        Long key = i;
-        Assertions.assertEquals(key, target.getAndLoadIfAbsent(key));
+        final long key = i;
+        Assertions.assertEquals(key, 
target.getAndLoadIfAbsent(key).longValue());
       }
 
-      Assertions.assertEquals(next, target.getAndLoadIfAbsent(next));
+      Assertions.assertEquals(next, 
target.getAndLoadIfAbsent(next).longValue());
       Assertions.assertNull(target.get(start));
 
       Assertions.assertEquals(SIZE + 1, counter.longValue());
diff --git 
a/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java 
b/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java
index 00f527955f8..91d38b1d670 100644
--- a/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java
+++ b/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java
@@ -62,8 +62,8 @@ public class CloseableUtilsTest
   @Test
   public void test_closeAll_array_loud()
   {
-    final Exception e = Assertions.assertThrows(
-        Exception.class,
+    final IOException e = Assertions.assertThrows(
+        IOException.class,
         () -> CloseableUtils.closeAll(
             quietCloseable,
             null,
@@ -75,9 +75,6 @@ public class CloseableUtilsTest
 
     assertClosed(quietCloseable, ioExceptionCloseable, quietCloseable2, 
runtimeExceptionCloseable);
 
-    // First exception
-    Assertions.assertInstanceOf(IOException.class, e);
-
     // Second exception
     Assertions.assertEquals(1, e.getSuppressed().length);
     Assertions.assertInstanceOf(IllegalArgumentException.class, 
e.getSuppressed()[0]);
@@ -86,8 +83,8 @@ public class CloseableUtilsTest
   @Test
   public void test_closeAll_list_loud()
   {
-    final Exception e = Assertions.assertThrows(
-        Exception.class,
+    final IOException e = Assertions.assertThrows(
+        IOException.class,
         () -> CloseableUtils.closeAll(
             Arrays.asList(
                 quietCloseable,
@@ -101,9 +98,6 @@ public class CloseableUtilsTest
 
     assertClosed(quietCloseable, ioExceptionCloseable, quietCloseable2, 
runtimeExceptionCloseable);
 
-    // First exception
-    Assertions.assertInstanceOf(IOException.class, e);
-
     // Second exception
     Assertions.assertEquals(1, e.getSuppressed().length);
     Assertions.assertInstanceOf(IllegalArgumentException.class, 
e.getSuppressed()[0]);
diff --git 
a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
 
b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
index b0e5eb00c6c..a310672439c 100644
--- 
a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
+++ 
b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
@@ -2377,13 +2377,13 @@ public class SegmentLocalCacheManager implements 
SegmentCacheManager
           log.makeAlert(
               e,
               "Failed to load segment in current location [%s], try next 
location if any",
-              location.getPath().getAbsolutePath()
-          ).addData("location", location.getPath().getAbsolutePath()).emit();
+              mountLocation.getPath().getAbsolutePath()
+          ).addData("location", 
mountLocation.getPath().getAbsolutePath()).emit();
 
           throw new SegmentLoadingException(
               "Failed to load segment[%s] in reserved location[%s]",
               dataSegment.getId(),
-              location.getPath().getAbsolutePath()
+              mountLocation.getPath().getAbsolutePath()
           );
         }
         finally {
diff --git a/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java 
b/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java
index 53b650e589e..b9a4a169c73 100644
--- a/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java
+++ b/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Assertions;
 
 import java.util.ArrayDeque;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
 
@@ -52,11 +53,14 @@ public class MockServiceClient implements ServiceClient
       final HttpResponseHandler<IntermediateType, FinalType> handler
   )
   {
-    final Expectation expectation = expectations.poll();
+    final Expectation expectation = Objects.requireNonNull(
+        expectations.poll(),
+        "No expectation configured for the next request"
+    );
 
     requestNumber++;
     Assertions.assertEquals(
-        expectation == null ? null : expectation.request,
+        expectation.request,
         requestBuilder,
         "request[" + requestNumber + "]"
     );
diff --git 
a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java
 
b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java
index b042ad69bd9..4cb83242da4 100644
--- 
a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java
+++ 
b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java
@@ -60,13 +60,17 @@ public class ImmutableDruidDataSourceTestUtils
    * test code
    * @param expected expected list
    * @param actual actual list
-   * @return
    */
-  public static boolean assertEquals(List<ImmutableDruidDataSource> expected, 
List<ImmutableDruidDataSource> actual)
+  public static void assertEquals(
+      @Nullable List<ImmutableDruidDataSource> expected,
+      @Nullable List<ImmutableDruidDataSource> actual
+  )
   {
     if (expected == null) {
-      return actual == null;
+      Assertions.assertNull(actual);
+      return;
     }
+    Assertions.assertNotNull(actual);
 
     Assertions.assertEquals(expected.size(), actual.size(),
         "expected and actual ImmutableDruidDataSource lists should be of equal 
size");
@@ -77,7 +81,6 @@ public class ImmutableDruidDataSourceTestUtils
           "ImmutableDruidDataSource's equalsForTesting()" + " method");
       }
     }
-    return true;
   }
 
   private static boolean contains(ImmutableDruidDataSource expected, 
List<ImmutableDruidDataSource> actualList)
diff --git 
a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java
 
b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java
new file mode 100644
index 00000000000..e924e9f5490
--- /dev/null
+++ 
b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.test.utils;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+public class ImmutableDruidDataSourceTestUtilsTest
+{
+  @Test
+  public void testListAssertEqualsRejectsNullActual()
+  {
+    Assertions.assertThrows(
+        AssertionError.class,
+        () -> 
ImmutableDruidDataSourceTestUtils.assertEquals(Collections.emptyList(), null)
+    );
+  }
+
+  @Test
+  public void testListAssertEqualsRejectsNullExpected()
+  {
+    Assertions.assertThrows(
+        AssertionError.class,
+        () -> ImmutableDruidDataSourceTestUtils.assertEquals(null, 
Collections.emptyList())
+    );
+  }
+}
diff --git 
a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
 
b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
index 73209a76a98..902132f1812 100644
--- 
a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
+++ 
b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
@@ -254,20 +254,21 @@ public class EarliestLatestAnySqlAggregator implements 
SqlAggregator
       case 1:
         theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, 
fieldName, null, outputType, null, true);
         break;
-      case 2:
-        Integer maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); // 
added not null check at the function
+      case 2: {
+        final int maxStringBytes = RexLiteral.intValue(rexNodes.get(1));
         theAggFactory = aggregatorType.createAggregatorFactory(
             aggregatorName,
             fieldName,
             null,
             outputType,
-            maxStringBytes.intValue(),
+            maxStringBytes,
             true
         );
         break;
-      case 3:
-        maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); // added not 
null check at the function for rexNode 1,2
-        boolean aggregateMultipleValues = 
RexLiteral.booleanValue(rexNodes.get(2));
+      }
+      case 3: {
+        final int maxStringBytes = RexLiteral.intValue(rexNodes.get(1));
+        final boolean aggregateMultipleValues = 
RexLiteral.booleanValue(rexNodes.get(2));
         theAggFactory = aggregatorType.createAggregatorFactory(
             aggregatorName,
             fieldName,
@@ -277,6 +278,7 @@ public class EarliestLatestAnySqlAggregator implements 
SqlAggregator
             aggregateMultipleValues
         );
         break;
+      }
       default:
         throw InvalidSqlInput.exception(
             "Function [%s] expects 1 or 2 or 3 arguments but found [%s]",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to