Skip to content

fix(excel-import): guard excelReader.close() against null in finally - #2042

Merged
openai0229 merged 2 commits into
OtterMind:mainfrom
Aias00:fix/2033-excel-reader-npe
Jul 24, 2026
Merged

openai0229 merged 2 commits into
OtterMind:mainfrom
Aias00:fix/2033-excel-reader-npe

Conversation

@Aias00

@Aias00 Aias00 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #2033

Summary

In DbExcelTableServiceImpl, ExcelReader excelReader = null is assigned via EasyExcel.read(...).build() inside a try. If build() (or read) throws — e.g. a corrupt/IO-error file — excelReader is still null, and the finally { excelReader.close(); } block throws a NullPointerException that masks the real root cause. Added a null-check before close() at both import sites.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results: mvn -B -q -f chat2db-community-server/pom.xml -pl chat2db-community-domain/chat2db-community-domain-core -am -Dmaven.test.skip=true compile -> BUILD SUCCESS.
  • Manual verification: When build() throws, excelReader remains null, the guarded finally skips close(), and the original exception propagates via the catch (Exception e) { throw new RuntimeException(e); }.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: N/A.
  • Database or driver compatibility: N/A.
  • Network, privacy, or security: N/A.
  • Community / Local / Pro boundary: N/A.
  • Backward compatibility: Only changes the failure path from "NPE masks real error" to "real error propagates"; success path unchanged.

Reviewer map

  • Start here: DbExcelTableServiceImpl.java finally blocks at the two import methods — excelReader.close(); -> if (excelReader != null) { excelReader.close(); }.
  • Failure condition: A NullPointerException from excelReader.close() still masks the real parse/IO error.
  • Rollback or disable path: Revert this single commit.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: The fix, verification, and PR description were produced with Claude Code assistance.

ExcelReader is assigned via EasyExcel.read(...).build() inside the try;
if build() throws, excelReader is still null and the finally block's
excelReader.close() throws NPE, masking the real cause. Null-check
before close at both import sites.

Fixes OtterMind#2033

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 24, 2026 09:13
@Aias00
Aias00 requested a review from openai0229 as a code owner July 24, 2026 09:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@openai0229 openai0229 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.

Reviewed both Excel reader cleanup paths. The null guards preserve the original initialization failure instead of masking it with a finally-block NPE; no blocking issue found.

@openai0229
openai0229 merged commit 8648e40 into OtterMind:main Jul 24, 2026
16 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Excel import NPE in finally masks the real exception when EasyExcel.read(...).build() throws

3 participants