Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4662

StreamResult closes outputstream early

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.5.5
    • Component/s: None
    • Labels:
      None

      Description

      We recently upgraded from struts 2.3.x to 2.5.2 at our workplace. One of the changes we noticed was with stream result - if an error occurs, the output stream is automatically closed and no response is sent to the user (ignoring our custom error-500 page). The content-length of the response is thus 0 - a blank page.

      This is occuring due to the addition of try-with-resources. In 2.3.x, the output stream wasn't set until after we find the input stream, like so:

      try {
         get inputStream
         if (inputStream == null)
              throw Exception
         get outputStream
      } finally {
         if inputStream != null inputStream.close()
         if outputStream != null outputStream.close()
      }
      

      However, in 2.5, this was changed to use a try-with-resources on the output stream by ticket WW-4515 (https://git-wip-us.apache.org/repos/asf?p=struts.git;a=commit;h=3fab155b4cc530ca3ca0b69299ddcb348eb5f26d):

      try (OutputStream oOutput = oResponse.getOutputStream()) {
      // ...
      }
      

      So, when we throw an error, the stream is closed and nothing further is written.

      Is this intended behaviour? Is there an alternate solution to show our own error pages now (with stack trace?)?

        Issue Links

          Activity

          Hide
          hudson Hudson added a comment -

          SUCCESS: Integrated in Jenkins build Struts-JDK7-master #514 (See https://builds.apache.org/job/Struts-JDK7-master/514/)
          WW-4662 Partially reverts try-with-resources introduced with WW-4515 (lukaszlenart: rev 92c54de11030d6f6325386dd24ba92efb9f34a90)

          • (edit) core/src/main/java/org/apache/struts2/result/StreamResult.java
          Show
          hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #514 (See https://builds.apache.org/job/Struts-JDK7-master/514/ ) WW-4662 Partially reverts try-with-resources introduced with WW-4515 (lukaszlenart: rev 92c54de11030d6f6325386dd24ba92efb9f34a90) (edit) core/src/main/java/org/apache/struts2/result/StreamResult.java
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 92c54de11030d6f6325386dd24ba92efb9f34a90 in struts's branch refs/heads/master from Lukasz Lenart
          [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=92c54de ]

          WW-4662 Partially reverts try-with-resources introduced with WW-4515

          Show
          jira-bot ASF subversion and git services added a comment - Commit 92c54de11030d6f6325386dd24ba92efb9f34a90 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=92c54de ] WW-4662 Partially reverts try-with-resources introduced with WW-4515
          Hide
          lukaszlenart Lukasz Lenart added a comment - - edited

          Old behaviour was restored

          Show
          lukaszlenart Lukasz Lenart added a comment - - edited Old behaviour was restored
          Hide
          lukaszlenart Lukasz Lenart added a comment -

          It was rather unintended

          Show
          lukaszlenart Lukasz Lenart added a comment - It was rather unintended

            People

            • Assignee:
              Unassigned
              Reporter:
              MichaelHum Michael Hum
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development