Skip to content

fix: prevent NPE when isFinished() is called before DataDriver init#17440

Merged
JackieTien97 merged 2 commits intomasterfrom
fixNPE-0408
Apr 8, 2026
Merged

fix: prevent NPE when isFinished() is called before DataDriver init#17440
JackieTien97 merged 2 commits intomasterfrom
fixNPE-0408

Conversation

@shuwenwei
Copy link
Copy Markdown
Member

Summary

Fix NullPointerException that occurs when isFinished() is called on DataDriver
before the query data source is properly initialized.

Problem

When DataDriver initializes but fails to acquire the read lock (returning
UNFINISHED_QUERY_DATA_SOURCE), calling isFinished() on the driver would still
invoke root.isFinished(). This triggers a chain of calls:
Driver.isFinished() -> SingleDeviceViewOperator.isFinished() -> hasNextWithTimer() -> ... -> AbstractSeriesScanOperator.hasNext() -> SeriesScanUtil.hasNextFile() -> dataSource.hasNextSeqResource() // NPE: dataSource is null

The root cause is that SeriesScanUtil.dataSource is only set during
initQueryDataSource(), which may not complete if the data source is unfinished.

Solution

Add an isInit() method to Driver and check it in isFinishedInternal():

  • Driver.isFinishedInternal() now checks (isInit() && root.isFinished())
    instead of just root.isFinished()
  • DataDriver.isInit() returns the init field
  • SchemaDriver.isInit() returns true (always initialized)

This ensures that child operator methods are not called until the driver
is properly initialized.

Testing

Added DataDriverTest.testCallIsFinishedBeforeDataSourcePrepared() to verify
the fix works correctly when the query returns null data source.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 39.75%. Comparing base (e801885) to head (6e3be29).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
.../db/queryengine/execution/driver/SchemaDriver.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17440      +/-   ##
============================================
- Coverage     39.75%   39.75%   -0.01%     
  Complexity      312      312              
============================================
  Files          5135     5135              
  Lines        346996   347002       +6     
  Branches      44212    44213       +1     
============================================
- Hits         137959   137958       -1     
- Misses       209037   209044       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JackieTien97 JackieTien97 merged commit cfce7d9 into master Apr 8, 2026
30 checks passed
@JackieTien97 JackieTien97 deleted the fixNPE-0408 branch April 8, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants