@ewie sounds like a bug... let me fix it.
 @ewie should be fixed by https://github.com/netty/netty/pull/5877
 Fixed by https://github.com/netty/netty/pull/5877

HttpUtil.getContentLength(HttpMessage, long) throws unexpected NumberFormatException
The Javadocs of `HttpUtil.getContentLength(HttpMessage, long)` and its `int` overload state that the provided default value is returned if the Content-Length value is not a number. `NumberFormatException` is thrown instead [1] causing the method to behave like `HttpUtil.getContentLength(HttpMessage)` where the exception is explicitly documented for this case.

[1] https://github.com/netty/netty/blob/149916d052180dd2b0e0e98598f349454ea200ba/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java#L187

codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
index 0d9433c698b..4d165088e67 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java
@@ -184,7 +184,11 @@ public static long getContentLength(HttpMessage message) {
     public static long getContentLength(HttpMessage message, long defaultValue) {
         String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
         if (value != null) {
-            return Long.parseLong(value);
+            try {
+                return Long.parseLong(value);
+            } catch (NumberFormatException ignore) {
+                return defaultValue;
+            }
         }
 
         // We know the content length if it's a Web Socket message even if

diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java
index 1e9615ce8f5..93478d645d0 100644
--- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java
+++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java
@@ -100,4 +100,13 @@ public void testGetMimeType() {
         message.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=utf-8");
         assertEquals("text/html", HttpUtil.getMimeType(message));
     }
+
+    @Test
+    public void testGetContentLengthDefaultValue() {
+        HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
+        assertNull(message.headers().get(HttpHeaderNames.CONTENT_LENGTH));
+        message.headers().set(HttpHeaderNames.CONTENT_LENGTH, "bar");
+        assertEquals("bar", message.headers().get(HttpHeaderNames.CONTENT_LENGTH));
+        assertEquals(1L, HttpUtil.getContentLength(message, 1L));
+    }
 }
