[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-104?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Devin Han reopened ODFTOOLKIT-104:
----------------------------------

      Assignee:     (was: datanucleus)

Feedback from user, this issue still exists on 64bits Linux plateform, so 
reopen this issue.

I found a bug in ODFDOM that maybe the reason of this issue. see the following 
code from OdfPackage

    // Initialize using memory
    private void initializeZip(InputStream odfStream) throws Exception {
        ByteArrayOutputStream tempBuf = new ByteArrayOutputStream();
        StreamHelper.transformStream(odfStream, tempBuf);
        byte[] mTempByteBuf = tempBuf.toByteArray();
        tempBuf.close();         
---------------------------------------------------------------------------------------------------------->!!!!!!!!!!!!!!
 odfStream doesn't close
        if (mTempByteBuf.length < 3) {
            OdfValidationException ve = new 
OdfValidationException(OdfPackageConstraint.PACKAGE_IS_NO_ZIP, getBaseURI());
            if (mErrorHandler != null) {
                mErrorHandler.fatalError(ve);
            }
            throw new IllegalArgumentException(ve);
        }
        mZipFile = new ZipHelper(this, mTempByteBuf);
        readZip();
    }

In this method, the opened file stream isn't closed, which will lead OS can't 
recovery the file handler.

add the following code to the target:
// close the input stream to notify OS release file handle.
odfStream.close();

the update code has been commited to svn.

waiting for the user's new feedback to make sure this issue has been fixed.



Devin
                
> Create new spreadsheet, save it, load it, add a sheet, save it, then load it 
> causes failure
> -------------------------------------------------------------------------------------------
>
>                 Key: ODFTOOLKIT-104
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-104
>             Project: ODF Toolkit
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 0.8.5
>         Environment: Operating System: Linux
> Platform: PC
>            Reporter: datanucleus
>            Priority: Critical
>             Fix For: 0.8.7
>
>         Attachments: bug173-closedocument.patch, odf_load.zip
>
>
> Created an attachment (id=257)
> Test app demonstrating the problem
> Very basic test of creating a new spreadsheet, saving it, then loading it and 
> adding a new sheet with 2 columns, then saving it, and when loaded again it 
> gives
> java.lang.IllegalArgumentException: Document contains incorrect ODF Mediatype 
> 'null'
>         at 
> org.odftoolkit.odfdom.doc.OdfDocument.loadDocument(OdfDocument.java:356)
>         at 
> org.odftoolkit.odfdom.doc.OdfDocument.loadDocument(OdfDocument.java:344)
>         at org.datanucleus.test.Main.main(Main.java:51)
> Such things never happened with 0.6.16. Sample app attached, and is as below.
> This was reported previously via the forum/mailing list and issue 106 got 
> raised, but that hasn't addressed this basic problem. 
> If there is some missing step in the provided app (that makes it work) then 
> please let me know, but the documentation and examples for creating 
> spreadsheets seem lacking.
>             OdfDocument doc = null;
>             String filename = "test.ods";
>             File file = new File(filename);
>             System.out.println(">> file=" + file);
>             if (!file.exists())
>             {
>                 // ODF spreadsheet doesn't exist, so create
>                 System.out.println(">> OdfDocument.newSpreadsheetDocument()");
>                 doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
>                 System.out.println(">> OdfDocument.save(" + file + ")");
>                 doc.save(file);
>             }
>             // Load the document
>             System.out.println(">> OdfDocument.loadDocument(" + file + ")");
>             doc = OdfDocument.loadDocument(file);
>             // Add the table and its columns
>             OdfTable table = OdfTable.newTable(doc);
>             String sheetName = "FirstSheet";
>             table.setTableName(sheetName);
>             int numCols = 2;
>             for (int i=0;i<numCols;i++)
>             {
>                 OdfTableColumn col = table.appendColumn();
>             }
>             // Save the document
>             System.out.println(">> OdfDocument.save(" + file + ")");
>             doc.save(file);
>             // Load the document
>             System.out.println(">> OdfDocument.loadDocument(" + file + ")");
>             doc = OdfDocument.loadDocument(file);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to