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

ContainerRequestContext's overridden entity stream is not closed

XMLWordPrintable

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

      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);
          }
        }
      }
       

              jperkins-rhn James Perkins
              ben.manes Ben Manes
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: