Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3040

ContainerRequestContext's overridden entity stream is not closed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 4.7.2.Final
    • jaxrs
    • None

    Description

      The method ContainerRequestContext#setEntityStream is documented with,

      The runtime is responsible for closing the input stream.

      However when overriding this, the replaced stream is never explicitly closed. The following example prints Was closed? false when the request completes and the GC collects the stream. If this is not the responsibility of the framework, then the documentation should be clarified as it is unclear when and where the stream should be closed otherwise.

      @javax.ws.rs.ext.Provider
      public final class TestInterceptor implements ContainerRequestFilter {
      
        @Override
        public void filter(ContainerRequestContext requestContext) {
          requestContext.setEntityStream(new IsClosedInputStream(requestContext.getEntityStream()));
        }
      
        private static final class IsClosedInputStream extends FilterInputStream {
          private volatile boolean isClosed;
      
          protected IsClosedInputStream(InputStream source) {
            super(source);
          }
      
          @Override
          public void close() throws IOException {
            isClosed = true;
            super.close();
          }
      
          @Override
          protected void finalize() {
            System.err.println("Was closed? " + isClosed);
          }
        }
      }
       

      Attachments

        Activity

          People

            Unassigned Unassigned
            ben.manes Benjamin Manes (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: