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

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
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: [hidden email]
          Reporter: [hidden email]

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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

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

[hidden email] 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <[hidden email]> changed:

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

--- Comment #1 from Javen O'Neal <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

[hidden email] changed:

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

--- Comment #2 from [hidden email] ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

--- Comment #3 from Javen O'Neal <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

--- Comment #4 from Javen O'Neal <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #5 from Javen O'Neal <[hidden email]> ---
*** 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Javen O'Neal <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #6 from Javen O'Neal <[hidden email]> ---
*** 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Dominik Stadler <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #7 from Dominik Stadler <[hidden email]> ---
*** 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Alain Fagot Bearez <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #8 from Alain Fagot Bearez <[hidden email]> ---
*** 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Alain Fagot Bearez <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #9 from Alain Fagot Bearez <[hidden email]> ---
*** 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60102

Itan.riza <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|[hidden email],     |[hidden email]
                   |[hidden email], |
                   |[hidden email],      |
                   |[hidden email],             |
                   |[hidden email]           |

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]