Bug 52449

Summary: NullPointerException in org.apache.poi.xwpf.usermodel.XWPFStyles.commit()
Product: POI Reporter: Niels S. Hansen <nsh>
Component: XWPFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Example word document

Description Niels S. Hansen 2012-01-11 09:28:21 UTC
Created attachment 28137 [details]
Example word document

This has been observed in version 3.8-beta5

NullPointerException when reading and subsequently writing attached document.

java.lang.NullPointerException
	at org.apache.poi.xwpf.usermodel.XWPFStyles.commit(XWPFStyles.java:104)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:313)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:173)


Example program that reproduces the error:
---
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class GivesNullPointer {

    public static void main(String[] args) throws Exception {
        XWPFDocument doc = new XWPFDocument(new FileInputStream("Wordmerge.docx"));

        doc.write(new FileOutputStream("out.docx"));
    }
}
Comment 1 Nick Burch 2012-01-11 14:02:51 UTC
This is caused by the sample document having a glossary, which we don't currently handle. Unfortunately, the glossary has styles and settings, which we do, but we weren't properly reading the glossary styles/settings in. This broke at write time

Should be fixed in r1230045.