Copilot commented on code in PR #19823:
URL: https://github.com/apache/druid/pull/19823#discussion_r3685162564


##########
processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java:
##########
@@ -207,8 +208,12 @@ private void initDistribution()
         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");
+        for (int i = 0; i < nonNullEnumeratedValues.size(); i++) {
+          probabilities.add(new Pair<>(nonNullEnumeratedValues.get(i), 
nonNullEnumeratedProbabilities.get(i)));
         }

Review Comment:
   In `ENUMERATED` distribution, the code assumes `enumeratedValues` and 
`enumeratedProbabilities` have the same length. If they differ, this will throw 
`IndexOutOfBoundsException` when accessing 
`nonNullEnumeratedProbabilities.get(i)`. Consider validating the sizes up front 
and failing with a clear message.



##########
processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java:
##########
@@ -381,8 +381,8 @@ public void doesNotLoadIfPresent()
     @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;

Review Comment:
   `next` and `key` are declared as boxed `Long` values but are never intended 
to be null. Since this PR is removing unnecessary boxing (and addressing 
`java/non-null-boxed-variable`), these locals should be primitives too to avoid 
extra allocations and potential lingering CodeQL findings.



##########
sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java:
##########
@@ -254,20 +254,22 @@ public Aggregation toDruidAggregation(
       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)); // 
added not null check at the function

Review Comment:
   The inline comment about an "added not null check" is misleading here: 
`RexLiteral.intValue(...)` already returns a primitive `int` and there is no 
explicit nullness check in this line. Please remove or rewrite the comment so 
it reflects the actual behavior (or the specific upstream validation it refers 
to).
   
   This issue also appears on line 270 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to