Bug 56572 - Implementation of HSSFCellStyle does not match its contract
Summary: Implementation of HSSFCellStyle does not match its contract
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-28 15:26 UTC by Mayeul
Modified: 2014-05-29 11:45 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mayeul 2014-05-28 15:26:36 UTC
Hi, 

As define in the interface org.apache.poi.ss.usermodel.Cell, the method setStyle can accept a null value (from javadoc) : "If the value is null then the style information is removed causing the cell to used the default workbook style."

Or when I look at the implemenation in HSSFCell, I saw that: 
public void setCellStyle(CellStyle style) {
        setCellStyle( (HSSFCellStyle)style );
    }
    public void setCellStyle(HSSFCellStyle style) {
        // Verify it really does belong to our workbook
        style.verifyBelongsToWorkbook(_book);

        short styleIndex;
        if(style.getUserStyleName() != null) {
            styleIndex = applyUserCellStyle(style);
        } else {
            styleIndex = style.getIndex();
        }

        // Change our cell record to use this style
        _record.setXFIndex(styleIndex);
    }

So a null value is not checked and not taken into account.

Thanks,

Mayeul
Comment 1 Nick Burch 2014-05-28 16:40:17 UTC
How does XSSF behave in this case?

(i.e. is this a bug in the javadoc, or a hssf specific bit of missing functionality)
Comment 2 Mayeul 2014-05-29 09:30:16 UTC
Hi,

Xssf behaves as expected : 

public void setCellStyle(CellStyle style) {
    if(style == null) {
        if(_cell.isSetS()) _cell.unsetS();
    } else {
     ....
    }
}
Comment 3 Nick Burch 2014-05-29 11:40:34 UTC
Thanks for investigating, fixed in r1598258.
Comment 4 Mayeul 2014-05-29 11:45:22 UTC
I am really amazed by your responsiveness.
Glad to help and thanks a lot.

Mayeul