Bug 56392

Summary: [PATCH] IllegalArgumentException in IdentifierManager / XWPFDocument
Product: POI Reporter: Hannes Erven <hannes>
Component: XWPFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: pepaproch
Priority: P2 Keywords: PatchAvailable
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: file causing error
IdentifierManager initialised with IDs starting at 0.

Description Hannes Erven 2014-04-11 13:32:40 UTC
I have run into this issue:

http://stackoverflow.com/questions/18756484/getting-illegalarguementexception-value-for-parameter-id-was-out-of-bounds


The fix suggested there hasn't made it into trunk, and there also doesn't seem to be a bug report anyways. It is really that simple?
Comment 1 Nick Burch 2014-04-11 13:37:27 UTC
Do you have a file you could share which triggers the problem?
Comment 2 Hannes Erven 2014-04-11 14:41:31 UTC
Sorry, not at the moment, I got the exception just in a log. I'll have the program save the file for inspection next time.
It obviously affects only a very number of files anyways.
Comment 3 Nick Burch 2014-04-11 14:48:09 UTC
We like to have sample files that show the problem so we can include unit tests. That allows us to check we've really fixed the problem, and that it stays fixed as we go forward!

If you could catch the next failing document and contribute it, we can then verify if the proposed fix is the right one, fix it, and test it
Comment 4 Josef Procházka 2014-06-25 11:21:58 UTC
Created attachment 31750 [details]
file causing error

created or resaved by Libre Office 4.2.3.3 420m0(Build:3) (3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux)
Comment 5 Josef Procházka 2014-06-25 11:22:18 UTC
I am experiencing this error as well. It is caused by docx files created or resaved by Libre Office 4.2.3.3 420m0(Build:3) (3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux)

I have attached a file that caused the problem. 



stack trace

[Request processing failed; nested exception is java.lang.IllegalArgumentException: Value for parameter 'id' was out of bounds] with root cause
 java.lang.IllegalArgumentException: Value for parameter 'id' was out of bounds
	at org.apache.poi.util.IdentifierManager.reserve(IdentifierManager.java:80)
	at org.apache.poi.xwpf.usermodel.XWPFRun.<init>(XWPFRun.java:107)
	at org.apache.poi.xwpf.usermodel.XWPFRun.<init>(XWPFRun.java:146)
	at org.apache.poi.xwpf.usermodel.XWPFParagraph.buildRunsInOrderFromXml(XWPFParagraph.java:135)
	at org.apache.poi.xwpf.usermodel.XWPFParagraph.<init>(XWPFParagraph.java:88)
	at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:147)
	at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
	at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:124)

I am instantiating XWPFDocument  thi sway

        try (FileInputStream fis = new FileInputStream(inputFilename)) {
            doc = new XWPFDocument(fis);
        }
Comment 6 Melozzola 2015-01-06 12:41:59 UTC
Created attachment 32346 [details]
IdentifierManager initialised with IDs starting at 0.

Patch to solve 
java.lang.IllegalArgumentException: Value for parameter 'id' was out of bounds
when parsing docx files created with LibreOffice
Comment 7 Dominik Stadler 2015-03-11 20:32:37 UTC
This was actually fixed by checkin "Patch from rojotek from github-18 - Handle documents with a picture-only header" r1661908, I have added a small test with the document from here as test-case to verify that it also continues to work in the future.