Bug 44491

Summary: Old-style setting of POIFS properties doesn't work with POI 3.0.2 in all cases
Product: POI Reporter: Yegor Kozlov <yegor>
Component: POI OverallAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: The patch

Description Yegor Kozlov 2008-02-26 07:41:16 UTC
POI 3.0.2 includes handy accessors to DocumentSummary and Summary information
streams.

Unfortunately old-style setting of POIFS properties doesn't work any more in all
cases. By "old-style" I mean direct constructing 
of DocumentSummaryInformation and SummaryInformation from POIFSFileSystem.

"old-style" usage is important, this is how I discovered this bug just before
copying POI 3.0.2 to production. 


Consider two code snippets:

(1) set POIFS properties before constructing HSSFWorkbook (works fine)

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("test.xls"));
 
        //set POIFS properties after constructing HSSFWorkbook
        //(a piece of code that used to work up to POI 3.0.2)
        SummaryInformation summary1 =
(SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
        summary1.setTitle(title);
        //write the modified property back to POIFS
        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
        fs.createDocument(summary1.toInputStream(),
SummaryInformation.DEFAULT_STREAM_NAME);

        HSSFWorkbook wb = new HSSFWorkbook(fs);

        OutputStream out = new FileOutputStream(""test-saved.xls"");
        wb.write(out);
        out.close();


(2) set POIFS properties after constructing HSSFWorkbook (used to work up to POI
3.0.2, fails now)

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("test.xls"));
 
        HSSFWorkbook wb = new HSSFWorkbook(fs);

        //set POIFS properties after constructing HSSFWorkbook
        //(a piece of code that used to work up to POI 3.0.2)
        SummaryInformation summary1 =
(SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
        summary1.setTitle(title);
        //write the modified property back to POIFS
        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
        fs.createDocument(summary1.toInputStream(),
SummaryInformation.DEFAULT_STREAM_NAME);


        OutputStream out = new FileOutputStream(""test-saved.xls"");
        wb.write(out);
        out.close();


Unfortunately (2) doesn't work any more  with POI 3.0.2. See the unit test in
the patch.


I think I found a workaround but I don't want to commit it without discussing.
The idea is simple: don't read DocumentSummary and Summary
in constructor. Instead, read them on first call of
POIDocument.getSummaryInformation() or POIDocument.getDocumentSummaryInformation(). 

Nick, would you please confirm this change is OK to you?


Regards,
Yegor
Comment 1 Yegor Kozlov 2008-02-26 07:42:00 UTC
Created attachment 21594 [details]
The patch
Comment 2 Rainer Klute 2008-02-27 04:26:09 UTC
Since this is not an HPSF bug I don't care.
Comment 3 Nick Burch 2008-03-03 07:03:35 UTC
This sounds sane to me. I figured it'd be handy for them to be available to everyone, save each user needing to repeat the code to get at them (I was getting bored of coding it every time at least!)

Having them read on demand works for me too though, so I'll apply it in a sec
Comment 4 Nick Burch 2008-03-03 07:10:05 UTC
Patch committed