Bug 54645 - Infinite Loop in IntMapper
Summary: Infinite Loop in IntMapper
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows Server 2003
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-06 14:11 UTC by Imsand Li
Modified: 2013-03-06 16:02 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Imsand Li 2013-03-06 14:11:44 UTC
Hi, 

In my application I found from time to time some hanging Threads. The Threaddumps are always pointing to the POI IntMapper class

    at java.util.HashMap.get(java.lang.Object)
    at org.apache.poi.util.IntMapper.getIndex(java.lang.Object)
    at org.apache.poi.hssf.record.SSTRecord.addString(org.apache.poi.hssf.record.UnicodeString)
    at org.apache.poi.hssf.model.Workbook.addSSTString(org.apache.poi.hssf.record.UnicodeString)
    at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(org.apache.poi.ss.usermodel.RichTextString)

We are using POI 3.6 but since then, only some code clean up (0111e33d) happened. This problem probably exists in newer Versions too.


I even found some references in the internet with the same problem:
- http://mail-archives.apache.org/mod_mbox/poi-user/201212.mbox/%3Cloom.20121220T112250-206@post.gmane.org%3E
- http://cueabsorb.wordpress.com/2010/12/15/%E4%BD%BF%E7%94%A8hashmap%E5%AF%BC%E8%87%B4cpu-200%E6%88%96%E8%80%85%E5%AF%BC%E8%87%B4%E7%9A%84load-%E9%A3%99%E9%AB%98%E9%97%AE%E9%A2%98/
Comment 1 Nick Burch 2013-03-06 15:28:58 UTC
What are you doing to trigger it?

Is there any chance you could be allowing two different threads to work on the same open workbook? 

(POI is designed to allow multiple different threads to each access their own different workbooks, but it isn't designed to let multiple threads work on the very same workbook object)

As it stands, I can't see anything that might explain why the code would lock up in regular operation (other than a JVM bug)
Comment 2 Imsand Li 2013-03-06 15:54:55 UTC
(In reply to comment #1)
> What are you doing to trigger it?
I profiled the JVM to get the stacktrace. It's a race condition, as the application is already running several days.

> Is there any chance you could be allowing two different threads to work on
> the same open workbook? 

Yes. It seems like a new bug in our application circumvents the synchronization of the workbook.

I'm closing the bug.
Thx.
Comment 3 Nick Burch 2013-03-06 16:02:24 UTC
Just to confirm for anyone looking later and wondering about threading with POI:

Two threads, each working on different workbooks (or other file formats) should always be fine

Two threads, trying to work on the same workbook object (or same slideshow, word doc, poifsfilesystem etc) is not supported

Each workbook / filesystem / etc must only be worked on by one thread. Multiple threads must each work with their own objects