Repository: netty/netty
Issue: HttpObjectEncoder#isContentAlwaysEmpty cannot be overridden by subclasses
Labels: improvement

### Expected behavior

the `HttpObjectEncoder#isContentAlwaysEmpty()` method is package private, so subclasses can change its behavior. Currently Vert.x has a subclass extending `HttpObjectEncoder `.

### Actual behavior

the `HttpObjectEncoder#isContentAlwaysEmpty()` method is package private

### Steps to reproduce

n/a

### Minimal yet complete reproducer code (or URL to code)

n/a

### Netty version

4.1.8.Final

### JVM version (e.g. `java -version`)

n/a

### OS version (e.g. `uname -a`)

n/a

Issue comments:
@vietj so you say it is package private and it should be not package-private ? Whats your use-case ?
my use case is to not send content in a response to HEAD, Vert.x has a special subclass (that you actually created) of `HttpObjectEncoder` that forces the usage of direct buffers, so we cannot use the `HttpServerCodec` that handles it.

Another motivation is that we might want to handle the HEAD check with a custom implementation of `HttpMessage` (like a boolean) and not use an a FIFO queue of HttpMessage like in `HttpServerCodec`.
any news about this ?
Can you just create a PR for this change ?


On 26. May 2017 at 10:26:16, Julien Viet (notifications@github.com) wrote:

isContentAlwaysEmpty

sure I will
Fixed by https://github.com/netty/netty/pull/6788

Pull request review comments:
false positive
`{@code true}`
I tend to [agree with @jodastephen that `{@code ...}` is overhead for `true`, `false`, and `null`](http://blog.joda.org/2012/11/javadoc-coding-standards.html). 😄
And I fully acknowledge that this is bike-shedding, sorry so much for that.
![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png) Remove this unused method parameter "msg". [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://garage.netty.io/sonarqube/coding_rules#rule_key=squid%3AS1172)


Patch that resolved the issue:
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java
index 7ef528f365a..878a264ab68 100755
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java
@@ -195,7 +195,14 @@ private void encodeChunkedContent(ChannelHandlerContext ctx, Object msg, long co
         }
     }
 
-    boolean isContentAlwaysEmpty(@SuppressWarnings("unused") H msg) {
+    /**
+     * Determine whether a message has a content or not. Some message may have headers indicating
+     * a content without having an actual content, e.g the response to an HEAD or CONNECT request.
+     *
+     * @param msg the message to test
+     * @return {@code true} to signal the message has no content
+     */
+    protected boolean isContentAlwaysEmpty(@SuppressWarnings("unused") H msg) {
         return false;
     }
 
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java
index 29a11992ad5..a009df1145a 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java
@@ -112,7 +112,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> ou
     private final class HttpServerResponseEncoder extends HttpResponseEncoder {
 
         @Override
-        boolean isContentAlwaysEmpty(@SuppressWarnings("unused") HttpResponse msg) {
+        protected boolean isContentAlwaysEmpty(@SuppressWarnings("unused") HttpResponse msg) {
             return HttpMethod.HEAD.equals(queue.poll());
         }
     }


Test patch: