Bug 48832 - NullPointerException at org.apache.poi.hpsf.MutableSection.getSize(MutableSection.java:328)
Summary: NullPointerException at org.apache.poi.hpsf.MutableSection.getSize(MutableSec...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-01 14:44 UTC by M.H.
Modified: 2010-05-26 11:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description M.H. 2010-03-01 14:44:07 UTC
I try to add meta data via SummaryInfo:

-----------
workbook.createInformationProperties();
            final SummaryInformation si = workbook.getSummaryInformation();
            if (si != null) {
                for (final Map.Entry<String, Object> e : summaryInfo.entrySet()) {
                    final String k = e.getKey().toLowerCase();
                    final Object o = e.getValue();
                    if (k != null && o != null) {
                        if ("author".equals(k)) {
                            si.setLastAuthor(si.getAuthor());
                            si.setAuthor(o.toString());
                        } else if ("appName".equals(k)) {
                            si.setApplicationName(o.toString());
                        } else if ("comments".equals(k)) {
                            si.setComments(o.toString());
                        } else if ("creationDate".equals(k) && o instanceof Date) {
                            si.setCreateDateTime((Date) o);
                        } else if ("keywords".equals(k)) {
                            si.setKeywords(o.toString());
                        } else if ("keywords".equals(k)) {
                            si.setKeywords(o.toString());
                        } else if ("subject".equals(k)) {
                            si.setSubject(o.toString());
                        } else if ("title".equals(k)) {
                            si.setTitle(o.toString());
                        }
                    }//else: entry unavailable
                }//next input summaryInfo
            }//else: SummaryInformation unavailable
----------------------

but when I save the workbook (via workbook.write(fos) ), I get this NPE:

----------------
    org.apache.poi.hpsf.HPSFRuntimeException
    	at org.apache.poi.hpsf.MutableSection.getSize(MutableSection.java:328)
    	at org.apache.poi.hpsf.MutablePropertySet.write(MutablePropertySet.java:230)
    	at org.apache.poi.POIDocument.writePropertySet(POIDocument.java:209)
    	at org.apache.poi.POIDocument.writeProperties(POIDocument.java:184)
    	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1169)
        ...
    Caused by:
    java.lang.NullPointerException
    	at org.apache.poi.hpsf.VariantSupport.write(VariantSupport.java:503)
    	at org.apache.poi.hpsf.MutableProperty.write(MutableProperty.java:116)
    	at org.apache.poi.hpsf.MutableSection.write(MutableSection.java:459)
    	at org.apache.poi.hpsf.MutableSection.calcSize(MutableSection.java:348)
    	at org.apache.poi.hpsf.MutableSection.getSize(MutableSection.java:319)
    	at org.apache.poi.hpsf.MutablePropertySet.write(MutablePropertySet.java:230)
    	at org.apache.poi.POIDocument.writePropertySet(POIDocument.java:209)
    	at org.apache.poi.POIDocument.writeProperties(POIDocument.java:184)
    	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1169)
        ...
---------------------
Comment 1 Nick Burch 2010-05-26 11:12:56 UTC
I'm unable to replicate this.

I've added a new unit test which shows that you can create a document with no properties, add them in, save and reload, change some more, and all works fine with no errors:
   org.apache.poi.hpsf.basic.TestHPSFBugs

I'd suggest you take a look at that to see how to work with properties. If you're still having problems, please create a failing unit test and upload that