Discussion:
ConcurrentModificationException and NullPointerException when accessing concurrentyl
Pavel Drankov
2018-08-23 10:46:59 UTC
Permalink
Hi,

I have an instance of SXSSFSheet and when I'm trying to fill it with
values concurrently, such exceptions occurs:

java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1247) ~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1242) ~[na:1.8.0_152]
at org.apache.poi.xssf.streaming.SXSSFSheet.getRowNum(SXSSFSheet.java:1851)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFRow.getRowNum(SXSSFRow.java:218)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFCell.getRowIndex(SXSSFCell.java:84)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFCell.setHyperlink(SXSSFCell.java:649)
~[poi-ooxml-3.14.jar:3.14]

java.lang.NullPointerException: null
at
org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(AutoSizeColumnTracker.java:302)
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(SXSSFSheet.java:1834)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1813)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:155)
~[poi-ooxml-3.14.jar:3.14]

I put synchronization on the object access and it works fine now, but is
not it an issue? Should the SXSSFCell and SXSSFSheet objects be thread safe?

Best wishes,
Pavel
Greg Woolsey
2018-08-23 16:22:10 UTC
Permalink
See question 20 from the POI FAQ [1]. Accessing the same document objects
from multiple threads is not supported.

[1] https://poi.apache.org/faq.html
Post by Pavel Drankov
Hi,
I have an instance of SXSSFSheet and when I'm trying to fill it with
java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1247) ~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1242) ~[na:1.8.0_152]
at org.apache.poi.xssf.streaming.SXSSFSheet.getRowNum(SXSSFSheet.java:1851)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFRow.getRowNum(SXSSFRow.java:218)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFCell.getRowIndex(SXSSFCell.java:84)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFCell.setHyperlink(SXSSFCell.java:649)
~[poi-ooxml-3.14.jar:3.14]
java.lang.NullPointerException: null
at
org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(AutoSizeColumnTracker.java:302)
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(SXSSFSheet.java:1834)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1813)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:155)
~[poi-ooxml-3.14.jar:3.14]
I put synchronization on the object access and it works fine now, but is
not it an issue? Should the SXSSFCell and SXSSFSheet objects be thread safe?
Best wishes,
Pavel
Pavel Drankov
2018-08-23 19:23:35 UTC
Permalink
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document objects
from multiple threads is not supported.
Good, but can we make these objects thread safe at least?
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document objects
from multiple threads is not supported.
[1] https://poi.apache.org/faq.html
Post by Pavel Drankov
Hi,
I have an instance of SXSSFSheet and when I'm trying to fill it with
java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1247)
~[na:1.8.0_152]
Post by Pavel Drankov
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1242)
~[na:1.8.0_152]
Post by Pavel Drankov
at
org.apache.poi.xssf.streaming.SXSSFSheet.getRowNum(SXSSFSheet.java:1851)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFRow.getRowNum(SXSSFRow.java:218)
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFCell.getRowIndex(SXSSFCell.java:84)
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFCell.setHyperlink(SXSSFCell.java:649)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
java.lang.NullPointerException: null
at
org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(AutoSizeColumnTracker.java:302)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(SXSSFSheet.java:1834)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1813)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:155)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
I put synchronization on the object access and it works fine now, but is
not it an issue? Should the SXSSFCell and SXSSFSheet objects be thread safe?
Best wishes,
Pavel
Greg Woolsey
2018-08-23 21:39:27 UTC
Permalink
You can investigate the source and see, but the reason POI is not thread
safe is because it is extremely difficult to do with projects based on
XML-Beans. The POI team has no plans to revisit the subject at this point.
Post by Pavel Drankov
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document
objects
Post by Greg Woolsey
from multiple threads is not supported.
Good, but can we make these objects thread safe at least?
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document
objects
Post by Greg Woolsey
from multiple threads is not supported.
[1] https://poi.apache.org/faq.html
Post by Pavel Drankov
Hi,
I have an instance of SXSSFSheet and when I'm trying to fill it with
java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1247)
~[na:1.8.0_152]
Post by Pavel Drankov
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1242)
~[na:1.8.0_152]
Post by Pavel Drankov
at
org.apache.poi.xssf.streaming.SXSSFSheet.getRowNum(SXSSFSheet.java:1851)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFRow.getRowNum(SXSSFRow.java:218)
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFCell.getRowIndex(SXSSFCell.java:84)
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFCell.setHyperlink(SXSSFCell.java:649)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
java.lang.NullPointerException: null
at
org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(AutoSizeColumnTracker.java:302)
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(SXSSFSheet.java:1834)
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(SXSSFSheet.java:1813)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:155)
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
I put synchronization on the object access and it works fine now, but
is
Post by Greg Woolsey
Post by Pavel Drankov
not it an issue? Should the SXSSFCell and SXSSFSheet objects be thread safe?
Best wishes,
Pavel
Dominik Stadler
2018-08-24 07:46:42 UTC
Permalink
Hi,

As the FAQ entry explains you need to synchronize access to a single
Workbook in your code, so the options are either doing that synchronization
whenever your threads access the workbook so only one thread is ever
accessing the workbook or doing the changes in multiple separate workbooks
and copying the results into the final workbook at the end in a single
thread.

It depends on your actual use-case which option is better suited.

Dominik.
Post by Greg Woolsey
You can investigate the source and see, but the reason POI is not thread
safe is because it is extremely difficult to do with projects based on
XML-Beans. The POI team has no plans to revisit the subject at this point.
Post by Pavel Drankov
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document
objects
Post by Greg Woolsey
from multiple threads is not supported.
Good, but can we make these objects thread safe at least?
Post by Greg Woolsey
See question 20 from the POI FAQ [1]. Accessing the same document
objects
Post by Greg Woolsey
from multiple threads is not supported.
[1] https://poi.apache.org/faq.html
Post by Pavel Drankov
Hi,
I have an instance of SXSSFSheet and when I'm trying to fill it with
java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.
nextEntry(TreeMap.java:1211)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[na:1.8.0_152]
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1247)
~[na:1.8.0_152]
Post by Pavel Drankov
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1242)
~[na:1.8.0_152]
Post by Pavel Drankov
at
org.apache.poi.xssf.streaming.SXSSFSheet.getRowNum(
SXSSFSheet.java:1851)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at org.apache.poi.xssf.streaming.SXSSFRow.getRowNum(SXSSFRow.
java:218)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFCell.getRowIndex(SXSSFCell.java:84)
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFCell.setHyperlink(
SXSSFCell.java:649)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
java.lang.NullPointerException: null
at
org.apache.poi.xssf.streaming.AutoSizeColumnTracker.updateColumnWidths(
AutoSizeColumnTracker.java:302)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushOneRow(
SXSSFSheet.java:1834)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.flushRows(
SXSSFSheet.java:1813)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
at
org.apache.poi.xssf.streaming.SXSSFSheet.createRow(
SXSSFSheet.java:155)
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
~[poi-ooxml-3.14.jar:3.14]
I put synchronization on the object access and it works fine now, but
is
Post by Greg Woolsey
Post by Pavel Drankov
not it an issue? Should the SXSSFCell and SXSSFSheet objects be
thread
Post by Pavel Drankov
Post by Greg Woolsey
Post by Pavel Drankov
safe?
Best wishes,
Pavel
Loading...