Search code examples
javaapache-poixmlbeans

Apache poi XSSFSheet.write() not finishing


I am running apache poi 4.0.0 with Java 8 and trying to fill a template with data and save it to an outputstream. This causes an issue upon writing the workbook to the destination path, but only when running in debug mode/on other machines. The template file has a size of 7.5 MB before filling it with data

I debugged it and found that the method call worksheet.save(out, xmlOptions); in XSSFSheet stops at some point.

Debug values for out:

class:              org.apache.poi.openxml4j.opc.internal.MemoryPackagePartOutputStream
part:               Name: /xl/worksheets/sheet10.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml
part-relationships: 3 relationship(s) = [/xl/worksheets/_rels/sheet10.xml.rels,/xl/worksheets/sheet10.xml,/xl/worksheets/_rels/sheet10.xml.rels]

Debug values for xmlOptions:

SAVE_USE_DEFAULT_NAMESPACE=null
CHARACTER_ENCODING=UTF-8
SAVE_OUTER=null
SAVE_SUGGESTED_PREFIXES={http://schemas.openxmlformats.org/drawingml/2006/chart=c, http://schemas.openxmlformats.org/wordprocessingml/2006/main=w, http://schemas.microsoft.com/office/word/2006/wordml=wne, http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes=vt, http://schemas.openxmlformats.org/presentationml/2006/main=p, urn:schemas-microsoft-com:office:word=w10, urn:schemas-microsoft-com:vml=v, http://schemas.openxmlformats.org/drawingml/2006/main=a, http://schemas.openxmlformats.org/officeDocument/2006/math=m, http://schemas.openxmlformats.org/officeDocument/2006/relationships=r, urn:schemas-microsoft-com:office:excel=x, urn:schemas-microsoft-com:office:office=o, http://schemas.openxmlformats.org/markup-compatibility/2006=ve, http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing=wp}
ENTITY_EXPANSION_LIMIT=1
SAVE_AGGRESSIVE_NAMESPACES=null
SAVE_SYNTHETIC_DOCUMENT_ELEMENT={http://schemas.openxmlformats.org/spreadsheetml/2006/main}worksheet

Going even deeper, it becomes clear that it fails on this method:

public void save(OutputStream os, XmlOptions options) throws IOException
    { XmlCursor cur = newCursorForce(); try { cur.save(os, makeInnerOptions(options)); } finally { cur.dispose(); } }

in XmlObjectBase, specifically on newCursorForce().

What can be the reason that this method fails on every other machine as well as on my machine in debug mode? If executed normally, the whole application runs smoothly.

EDIT:

I tried to dig deeper and am now at org.apache.xmlbeans.impl.store.Saver where it might fail at createSaveCur ( Cur c, XmlOptions options ), but not quite sure.

EDIT 2:

So far it seems like my application needed too much memory to proceed and therefore just stopped at that point without throwing OutOfMemoryException. I now increased the available memory and need to test a bit further if that is the true reason


If you need more info, feel free to ask.


Solution

  • As I already concluded in my second edit, it was really a memory issue. Executing the application with -Xms1G -Xmx4G as VM arguments, the application caused no issues and the runtime was pretty close to what I got while testing