nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.65k stars 1.42k forks source link

'Object reference not set to an instance of an object' in XSSFCell.ToString() #1347

Closed harrr closed 3 months ago

harrr commented 3 months ago

NPOI Version

2.7.0

File Type

Upload the Excel File

ASAP_Report_success.xlsx ASAP_Report_failed.xlsx Please attach your original Excel File to help us reproduce the issue

Reproduce Steps

The issue was found while running tests. The test downloads report about training process and tries to parse it. When test has read date from 'General info' tab, cell B6, cell.ToString() method is called to log test step result. When tests are run in parallel, this step fails with the following trace (file ASAP_Report_failed.xlsx): Object reference not set to an instance of an object.

at NPOI.Util.LocaleUtil.GetLocaleCalendar(TimeZone timeZone) at NPOI.Util.LocaleUtil.GetLocaleCalendar() at NPOI.SS.UserModel.DateUtil.GetJavaCalendar(Double date, Boolean use1904windowing, TimeZone timeZone, Boolean roundSeconds) at NPOI.SS.UserModel.DateUtil.GetJavaDate(Double date, Boolean use1904windowing) at NPOI.XSSF.UserModel.XSSFCell.get_DateCellValue() at NPOI.XSSF.UserModel.XSSFCell.ToString()

When I run a single test, it successfully passes (file ASAP_Report_success.xlsx).

Issue Description

'Object reference not set to an instance of an object' in XSSFCell.ToString() when running in parallel

tonyqus commented 3 months ago

What do you mean "running in parallel"? You have different threads calling XSSFCell.ToString() on the same cell?

harrr commented 3 months ago

What do you mean "running in parallel"? You have different threads calling XSSFCell.ToString() on the same cell?

No. Tests use different files. So cells are also different

tonyqus commented 3 months ago

I checked the following code. It has been commented out for a long time. Are you sure you are using 2.7.0? https://github.com/nissl-lab/npoi/blob/20a5569622b85119e6db1a987bdafc65d82c7029/main/SS/UserModel/DateUtil.cs#L517

And what's your environment and timezone? Are these tests running in Docker container?

harrr commented 3 months ago

I diged dipper to the solution and found another library, which used an older version. So, I guess, the issue may be closed