Skip to content

Conversation

@csbiy
Copy link
Contributor

@csbiy csbiy commented Jan 10, 2026

Purpose of the pull request

Fixes #788

The afterWorkbookDispose method throws NullPointerException when hasBeenInitializedSheetIndexMap contains null values.

What's changed?

Added a guard clause to skip null entries in the map before accessing getSheet().

Before:

for (WriteSheetHolder writeSheetHolder : writeSheetHolderMap.values()) {
    if (writeSheetHolder.getSheet() == null  // NPE here when writeSheetHolder is null
            || !(writeSheetHolder.getSheet() instanceof SXSSFSheet)) {
        continue;
    }

After:

for (WriteSheetHolder writeSheetHolder : writeSheetHolderMap.values()) {
    // map can contain null entries
    if (writeSheetHolder == null) {
        continue;
    }
    if (writeSheetHolder.getSheet() == null
            || !(writeSheetHolder.getSheet() instanceof SXSSFSheet)) {
        continue;
    }

Checklist

csbiy added 2 commits January 10, 2026 17:26
Add null check for writeSheetHolder before accessing its methods
to prevent NullPointerException when the map contains null values.

Fixes apache#788
Map can contain null writeSheetHolder values, causing NPE when
accessing getSheet(). Added guard clause for null entries.

Fixes apache#788
@delei
Copy link
Member

delei commented Jan 10, 2026

Hi, @csbiy Welcome!

BTW, Could you please add th code for the unit test?

@csbiy
Copy link
Contributor Author

csbiy commented Jan 10, 2026

Hi, @delei thanks for the welcome!
I've added the unit test code as requested.
Please let me know if you’d like me to make any changes.

Copy link
Member

@delei delei left a comment

Choose a reason for hiding this comment

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

LGTM

@delei delei added the PR: first-time contributor first-time contributor label Jan 28, 2026
@delei delei merged commit 29483d3 into apache:main Jan 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: first-time contributor first-time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] NullPointerException in DimensionWorkbookWriteHandler.afterWorkbookDispose: 60

2 participants