You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/09/09 23:57:39 UTC

[Bug 60102] New: Unable to write XWPFDocument opened from Http InputStream

https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

            Bug ID: 60102
           Summary: Unable to write XWPFDocument opened from Http
                    InputStream
           Product: POI
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: dev@poi.apache.org
          Reporter: kenneth_lau@yahoo.com

Created attachment 34228
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34228&action=edit
Word docx file failed to write

docx XWPFDocument opened from FileInputStream failed to write out to a new
FileOutputStream

Here's the stacktrace --

org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Rule M2.4
exception : this error should NEVER happen! Please raise a bug at
https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach a file that
triggers it, thanks!
    at
org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:343)
    at
org.apache.poi.openxml4j.opc.internal.ContentTypeManager.removeContentType(ContentTypeManager.java:256)
    at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:958)
    at
org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:522)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.commit(XWPFDocument.java:716)
    at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:464)
    at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:211)

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <on...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
           Severity|normal                      |enhancement
            Version|3.14-FINAL                  |3.15-dev
             Status|RESOLVED                    |REOPENED
            Summary|Unable to write             |Improve error message when
                   |XWPFDocument opened from    |writing a document that has
                   |Http InputStream            |been closed

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Unable to write XWPFDocument opened from Http InputStream

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

kenneth_lau@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEEDINFO                    |RESOLVED

--- Comment #2 from kenneth_lau@yahoo.com ---
I've debugged into the issue further. The problem is reproduced after the
OutputStream is closed by mistake after the first write.

Change test case test60102() to following --


// Write out to a file
    File outfile = TempFile.createTempFile("60102-resaved", "docx");
    OutputStream fos = new FileOutputStream(outfile);
    doc.write(fos);
    fos.close();
    doc.write(fos);


The second doc.write(fos) failed because OutputStream was closed by mistake.

The exception message was misleading. However, I've consider this is a usage
error.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <on...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |saikiran551@gmail.com

--- Comment #6 from Javen O'Neal <on...@apache.org> ---
*** Bug 60967 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Alain Fagot Bearez <Al...@cua.li> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |limesdevelopment@gmail.com

--- Comment #9 from Alain Fagot Bearez <Al...@cua.li> ---
*** Bug 59158 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbenagaraj86@gmail.com

--- Comment #7 from Dominik Stadler <do...@gmx.at> ---
*** Bug 61987 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

--- Comment #4 from Javen O'Neal <on...@apache.org> ---
Created attachment 34231
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34231&action=edit
Replace OpenXML4J return boolean with throws OpenXML4JException

(In reply to Javen O'Neal from comment #3)
> I have not yet implemented throwing an exception when writing an open
> document to a closed output stream.
> OutputStream out;
> out.close();
> doc.write(out);

To get this one closed, we're going to have to make quite a few changes to 
methods in org.apache.poi.openxml4j.opc.internal.
These methods currently catch exceptions, occasionally log the error to the
POILogger, and then return a boolean success value.
These will need to be replaced with void-returning functions that raise an
exception. This will eliminate the need to check a return code, enable the POI
logger, and check the logs.

A quick glance at the source code history reveals that the OpenXML4j classes
have returned boolean success rather than throwing exceptions. Perhaps this is
because this library originated from a C project rewritten in Java without
replacing the C idioms with Java idioms.
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java?revision=738842&view=markup#l41

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Unable to write XWPFDocument opened from Http InputStream

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <on...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Javen O'Neal <on...@apache.org> ---
I am unable to reproduce this in the latest nightly build of POI (r1755847).

Could you either check this against 3.15-beta2 or later a nightly, or produce a
unit test that produces the error seen in comment 0?
Apache commons collections was recently added as a dependency and will need to
be added to your class path.
https://builds.apache.org/job/POI/lastSuccessfulBuild/artifact/build/dist/

Here's my test case:

@Test
public void test60102() throws Exception {
    // read in from a java.io.File
    //XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60102.docx");

    // or read in from a java.io.FileInputStream
    File infile = POIDataSamples.getDocumentInstance().getFile("60102.docx");
    InputStream fis = new FileInputStream(infile);
    XWPFDocument doc = new XWPFDocument(fis);

    // Write out to a file
    File outfile = TempFile.createTempFile("60102-resaved", "docx");
    OutputStream fos = new FileOutputStream(outfile);
    doc.write(fos);
    fos.close();

    // Write out to a byte array output stream
    XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
    doc2.close();

    doc.close();
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Itan.riza <Mr...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|cbenagaraj86@gmail.com,     |Mriza2467@gmail.com
                   |limesdevelopment@gmail.com, |
                   |saikiran551@gmail.com,      |
                   |skn361@163.com,             |
                   |yongfeid@sina.com           |

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

--- Comment #3 from Javen O'Neal <on...@apache.org> ---
Throw IOException when writing a closed document implemented in r1760206
OutputStream out;
doc.close();
doc.write(out);

I have not yet implemented throwing an exception when writing an open document
to a closed output stream.
OutputStream out;
out.close();
doc.write(out);

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <on...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |skn361@163.com

--- Comment #5 from Javen O'Neal <on...@apache.org> ---
*** Bug 59559 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Alain Fagot Bearez <Al...@cua.li> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yongfeid@sina.com

--- Comment #8 from Alain Fagot Bearez <Al...@cua.li> ---
*** Bug 59806 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Unable to write XWPFDocument opened from Http InputStream

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

kenneth_lau@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |3.14-FINAL
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60102] Improve error message when writing a document that has been closed

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |64861


Referenced Bugs:

https://bz.apache.org/bugzilla/show_bug.cgi?id=64861
[Bug 64861] Error should never happen
-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org