Bug 65065 - NullPointerException in org.apache.poi.xssf.usermodel.XSSFCellStyle#cloneStyleFrom
Summary: NullPointerException in org.apache.poi.xssf.usermodel.XSSFCellStyle#cloneStyl...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.1.2-FINAL
Hardware: PC Mac OS X 10.1
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-07 12:25 UTC by liugenshui2012
Modified: 2021-07-28 21:25 UTC (History)
0 users



Attachments
the causing Excel file (17.97 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2021-01-08 02:43 UTC, liugenshui2012
Details

Note You need to log in before you can comment on or make changes to this bug.
Description liugenshui2012 2021-01-07 12:25:25 UTC
Exception:
Exception in thread "main" java.lang.NullPointerException
	at org.apache.poi.xssf.model.StylesTable.getNumberFormatId(StylesTable.java:273)
	at org.apache.poi.xssf.model.StylesTable.putNumberFormat(StylesTable.java:295)
	at org.apache.poi.xssf.usermodel.XSSFDataFormat.getFormat(XSSFDataFormat.java:52)
	at org.apache.poi.xssf.usermodel.XSSFCellStyle.cloneStyleFrom(XSSFCellStyle.java:185)
	at com.genshui.excel.ExcelStyleTest.copyCellStyle(ExcelStyleTest.java:56)
	at com.genshui.excel.ExcelStyleTest.main(ExcelStyleTest.java:29)


it actually happened in org.apache.poi.xssf.model.StylesTable#getNumberFormatId when the map numberFormats has a null value
Comment 1 Andreas Beeker 2021-01-07 12:29:50 UTC
as usual: please attach the causing Excel file
Comment 2 liugenshui2012 2021-01-08 02:43:10 UTC
Created attachment 37693 [details]
the causing Excel file

the causing Excel file
Comment 3 liugenshui2012 2021-01-08 02:44:52 UTC
(In reply to Andreas Beeker from comment #1)
> as usual: please attach the causing Excel file

the causing Excel file see Comment 2
Comment 4 PJ Fanning 2021-07-28 21:25:45 UTC
I wrote a test case that parsed the attached xlsx and tried to clone all its styles and had no issues (latest poi trunk code). In the snippet below, I renamed the test file. 

```
    void test65065() throws IOException {
        try (XSSFWorkbook wb = openSampleWorkbook("bug65065.xlsx")) {
            int size = wb.getStylesSource().getNumCellStyles();
            for (int i = 0; i < size; i++) {
                XSSFCellStyle style = wb.getStylesSource().getStyleAt(i);
                wb.createCellStyle().cloneStyleFrom(style);
            }
        }
    }
```