Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2246

DirectByteBufferDeallocator does not support android

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.3.6.Final, 2.2.25.Final
    • 2.3.4.Final
    • Core
    • None
    • Hide

      When test a post request with payload with Undertow server using the following handler function, it throws exception.

      public class TestHandler implements HttpHandler{

      @Override
      public void handleRequest(final HttpServerExchange exchange) throws Exception{

          HeaderMap headers = exchange.getRequestHeaders();

         if (headers.contains("content-length"){

             Integer contentLength = Integer.parseInt(headers.get("content-length").getFirst());
             if (contentLength > 0)

      {            byte[] body = new byte[contentLength];           exchange.getInputStream().read(body, 0, contentLength);        }

       

        }

      exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
      exchange.getResponseSender().send("read input ok");

      }

      }

      Show
      When test a post request with payload with Undertow server using the following handler function, it throws exception. public class TestHandler implements HttpHandler{ @Override public void handleRequest(final HttpServerExchange exchange) throws Exception{     HeaderMap headers = exchange.getRequestHeaders();    if (headers.contains("content-length"){        Integer contentLength = Integer.parseInt(headers.get("content-length").getFirst());        if (contentLength > 0) {            byte[] body = new byte[contentLength];           exchange.getInputStream().read(body, 0, contentLength);        }     } exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender().send("read input ok"); } }

      This class pulls system property "java.specification.version" and expects the value to be an integer or starts with 1. However on Android, this value is always 0.9. Therefore the code is broken at 

      Integer.parseInt(versionString).

      This bug directly impacts usage of HttpServerExchange.getInputStream().read() function.   

      See error log:

      Caused by: java.lang.NumberFormatException: For input string: "0.9"
              at java.lang.Integer.parseInt(Integer.java:747)
              at java.lang.Integer.parseInt(Integer.java:865)
              at io.undertow.server.DirectByteBufferDeallocator.<clinit>(DirectByteBufferDeallocator.java:28)
              at io.undertow.server.DirectByteBufferDeallocator.free(DirectByteBufferDeallocator.java:71) 
              at io.undertow.server.DefaultByteBufferPool.queueIfUnderMax(DefaultByteBufferPool.java:209) 
              at io.undertow.server.DefaultByteBufferPool.freeInternal(DefaultByteBufferPool.java:201) 
              at io.undertow.server.DefaultByteBufferPool.-$$Nest$mfreeInternal(Unknown Source:0) 
              at io.undertow.server.DefaultByteBufferPool$DefaultPooledBuffer.close(DefaultByteBufferPool.java:274) 
              at io.undertow.io.UndertowInputStream.read(UndertowInputStream.java:123) 

              rhn-cservice-bbaranow Bartosz Baranowski
              youngjunmorgan June Jorgensen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: