Skip to content

NullPointerException in HttpPostRequestEncoder encodeNextChunkUrlEncoded #9351

@emlittleworth

Description

@emlittleworth

Expected behavior

No NullPointerException.

Actual behavior

When given a certain input size, the encodeNextChunkUrlEncoded throws a NullPointerException in the following line

if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {

because the currentBuffer is null (which was set to the delimiter which was null). There seems to have been a similar issue in the past: #5478.

Steps to reproduce / Minimal yet complete reproducer code (or URL to code)

@Test
public void testWriteChunkedContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler());
    HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(req, false);

    int length = 8077 + 8096;
    char[] array = new char[length];
    Arrays.fill(array, 'a');
    String longText = new String(array);

    encoder.addBodyAttribute("data", longText);
    encoder.addBodyAttribute("moreData", "abcd");

    HttpRequest finalRequest = encoder.finalizeRequest();

    ch.writeOutbound(finalRequest);
    ch.writeOutbound(encoder);
    ch.flushOutbound();
}

Netty version

4.1

JVM version (e.g. java -version)

java version "1.8.0_111"

OS version (e.g. uname -a)

Darwin Kernel Version 18.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions