Skip to content

fix: address CodeQL control-flow and API warnings - #19820

Open
FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:codex/codeql-warning-control
Open

fix: address CodeQL control-flow and API warnings#19820
FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:codex/codeql-warning-control

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

What changed

  • Correct nonterminating/constant control flow, comparator contracts, iterator reuse, and redundant tests.
  • Make affected enum switches explicit in production code, tests, and the tracked SQL parser template.
  • Replace ad-hoc test implementations with existing contract-correct row and iterator types.
  • Document 21 intentional identity, ordering, optional-operation, and dual-evaluation contracts with narrow CodeQL suppressions.

Why

The current CodeQL snapshot reports 63 control-flow and API-contract warnings across 13 queries. This change addresses 61 of them:

  • 40 direct code or contract fixes
  • 21 precise suppressions for intentional semantics

The remaining two java/subtle-inherited-call alerts are in untracked output from protoc-gen-grpc-java. The current official gRPC Java generator still emits the same pattern. Editing target/ would not be durable, and excluding the query repository-wide would weaken future scanning, so those two generator-owned findings are intentionally not hidden by this PR.

Impact

The main behavioral fix prevents ByteBufferMinMaxOffsetHeap.siftDown from looping when no grandchild swap is needed. Comparator and iterator test helpers now satisfy their API contracts, enum evolution is handled explicitly, and SQL parser regeneration preserves the fixes.

Root cause

Some implementations intentionally use identity or partial ordering semantics that CodeQL cannot infer. Other findings were genuine missing enum cases, one-shot iterator wrappers, constant assertions, or incomplete comparison contracts. Six alerts originated in generated code; four map to the repository-owned SQL parser template and are fixed there, while two originate entirely in the external gRPC generator.

Checks

  • 11,919 focused test executions passed
  • 2 tests skipped
  • Processing compile and checkstyle passed
  • SQL parser regeneration and compilation passed
  • Focused multi-module reactors passed
  • git diff --check

Created by GPT-5.6-Sol.

@FrankChen021
FrankChen021 force-pushed the codex/codeql-warning-control branch from bb2f973 to 016d982 Compare July 30, 2026 16:26
InputRow retVal = new InputRow()
// Rows are ordered by timestamp, while equality retains the wrapped row's identity semantics.
// codeql[java/inconsistent-compareto-and-equals]
final InputRow retVal = new InputRow()
@FrankChen021
FrankChen021 marked this pull request as ready for review July 30, 2026 20:40
Copilot AI review requested due to automatic review settings July 30, 2026 20:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces CodeQL control-flow and API/contract findings across Druid by fixing a few real logic issues (notably a potential non-terminating heap sift) and by making intentional semantics explicit via narrow suppressions and clearer enum-switch handling. It touches core processing code, MSQ/controller paths, indexing metadata types, and a number of tests/utilities to align comparators/iterators with their contracts.

Changes:

  • Fix/control-flow and contract issues (e.g., ByteBufferMinMaxOffsetHeap.siftDown termination; comparator/iterator contract correctness in test helpers; remove redundant/constant assertions/tests).
  • Make enum switches explicit for newer ARRAY/COMPLEX cases and document intentional identity/ordering semantics with CodeQL suppressions.
  • Replace ad-hoc test rows/iterators with existing concrete implementations and add focused equality/hashCode coverage where needed.

Reviewed changes

Copilot reviewed 45 out of 45 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sql/src/main/codegen/templates/Parser.jj Adds explicit switch fall-through handling in the tracked SQL parser template to satisfy enum-switch expectations.
server/src/test/java/org/apache/druid/server/coordinator/simulate/WrappingScheduledExecutorService.java Fixes ScheduledFuture comparator contract in a test utility by adding stable ordering and identity equality.
server/src/test/java/org/apache/druid/server/coordinator/duty/CompactSegmentsTest.java Removes redundant constant assertions and aligns with final style.
server/src/test/java/org/apache/druid/segment/realtime/sink/SinkTest.java Replaces ad-hoc InputRow implementations with MapBasedInputRow for contract-correct test inputs.
server/src/test/java/org/apache/druid/rpc/NoDelayScheduledExecutorService.java Fixes ScheduledFuture comparator contract in a test utility by adding stable ordering and identity equality.
server/src/main/java/org/apache/druid/server/QueryResultPusher.java Handles additional error categories explicitly in the exception-to-counter mapping switch.
server/src/main/java/org/apache/druid/metadata/BasicDataSourceExt.java Documents and suppresses an intentional test-only accessor that can’t override a package-private superclass getter.
processing/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java Makes HashInputRow equality/comparison contract-correct for tests.
processing/src/test/java/org/apache/druid/segment/transform/TransformerTest.java Replaces ad-hoc InputRow with MapBasedInputRow for correct row behavior in tests.
processing/src/test/java/org/apache/druid/segment/transform/RowFunctionTest.java Simplifies test setup using MapBasedRow and stable timestamps.
processing/src/test/java/org/apache/druid/segment/data/VSizeColumnarIntsTest.java Adds explicit equals/hashCode tests for VSizeColumnarInts.
processing/src/test/java/org/apache/druid/segment/column/TypeStrategiesTest.java Fixes Comparable contract behavior in a test helper type and removes obsolete primitives usage.
processing/src/test/java/org/apache/druid/query/search/SearchQueryRunnerTest.java Removes a redundant type assertion in a search query test.
processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerTest.java Removes a logically redundant bounds check in a test loop.
processing/src/test/java/org/apache/druid/math/expr/VectorExprResultConsistencyTest.java Makes vector binding population explicitly reject unsupported types with a clear exception.
processing/src/test/java/org/apache/druid/java/util/common/guava/ConcatSequenceTest.java Fixes iterator reuse to ensure each iterator() call returns a fresh iterator as required.
processing/src/test/java/org/apache/druid/collections/IntSetTestUtility.java Removes a custom iterator wrapper and iterates IntIterator directly to satisfy iterator contracts.
processing/src/main/java/org/apache/druid/segment/incremental/SpatialDimensionRowTransformer.java Documents and suppresses intentional identity/ordering semantics in an InputRow wrapper.
processing/src/main/java/org/apache/druid/segment/filter/ExpressionFilter.java Makes array-element-type switch explicit for ARRAY/COMPLEX element types.
processing/src/main/java/org/apache/druid/segment/data/VSizeColumnarInts.java Implements value-based equals/hashCode consistent with compareTo.
processing/src/main/java/org/apache/druid/segment/data/CompressedBlockReader.java Removes a redundant assert in block-size validation while retaining state checks.
processing/src/main/java/org/apache/druid/query/topn/types/TopNColumnAggregatesProcessorFactory.java Makes strategy-type switching explicit for non-supported types.
processing/src/main/java/org/apache/druid/query/PrioritizedExecutorService.java Documents and suppresses intentional identity equality for prioritized future tasks.
processing/src/main/java/org/apache/druid/query/ordering/StringComparators.java Documents and suppresses intentional string reference-equality fast paths.
processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeap.java Fixes siftDown control flow to avoid non-terminating looping when no swap is needed.
processing/src/main/java/org/apache/druid/query/filter/InDimFilter.java Uses modern instanceof pattern matching to avoid redundant casts while preserving behavior.
processing/src/main/java/org/apache/druid/math/expr/ExpressionTypeFactory.java Makes array element-type switching explicit for ARRAY/COMPLEX.
processing/src/main/java/org/apache/druid/math/expr/ExpressionType.java Makes column-type to expression-type mapping switches explicit for nested ARRAY/COMPLEX cases.
processing/src/main/java/org/apache/druid/java/util/common/guava/FunctionalIterator.java Documents and suppresses intentional delegation of optional Iterator.remove.
processing/src/main/java/org/apache/druid/frame/field/FieldWriters.java Explicitly rejects unsupported ARRAY/COMPLEX array element types with a targeted exception.
processing/src/main/java/org/apache/druid/extendedset/intset/ConciseSet.java Documents and suppresses intentional non-short-circuit evaluation required for iterator advancement.
multi-stage-query/src/test/java/org/apache/druid/msq/kernel/controller/BaseControllerQueryKernelTest.java Makes stage initialization explicitly reject an invalid RETRYING phase.
multi-stage-query/src/main/java/org/apache/druid/msq/indexing/processor/SegmentGeneratorFrameProcessor.java Documents and suppresses intentional InputRow ordering/equality semantics during indexing.
multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerHolder.java Makes a state switch explicit for a RUNNING case in completion logic.
indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorTestBase.java Documents and suppresses intentional ordering vs equality semantics for sequence numbers in tests.
indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorStateTest.java Documents and suppresses intentional ordering vs equality semantics for sequence numbers in tests.
indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTaskRunnerTest.java Documents and suppresses intentional ordering vs equality semantics for sequence numbers in tests.
indexing-service/src/main/java/org/apache/druid/indexing/common/task/Tasks.java Documents and suppresses an intentional constant alignment check between independently-defined defaults.
extensions-core/kinesis-indexing-service/src/main/java/org/apache/druid/indexing/kinesis/KinesisSequenceNumber.java Documents and suppresses intentional ordering vs identity semantics for special Kinesis markers.
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaSequenceNumber.java Documents and suppresses intentional ordering/equality consistency for Kafka sequence numbers.
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaDataSourceMetadata.java Documents and suppresses intentional natural ordering that excludes non-ordering config components.
extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java Fixes redundant loop control flow to reflect the single-iteration behavior.
extensions-core/ec2-extensions/src/test/java/org/apache/druid/indexing/overlord/autoscaling/ec2/EC2AutoScalerTest.java Removes redundant constant assertions in EC2 autoscaler tests.
extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/expressions/BloomFilterExpressions.java Makes expression-type switching explicit for ARRAY/COMPLEX cases.
extensions-contrib/rabbit-stream-indexing-service/src/main/java/org/apache/druid/indexing/rabbitstream/RabbitSequenceNumber.java Documents and suppresses intentional ordering/equality consistency for Rabbit sequence numbers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.

Reviewed 45 of 45 changed files.


This is an automated review by Codex GPT-5.6-Sol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants