简体   繁体   English

jdk.incubator.httpclient中的NullPointerException

[英]NullPointerException in jdk.incubator.httpclient

I'm trying to new use new shiny httpclient from JDK10. 我正在尝试从JDK10使用新的闪亮的httpclient。 Code is pretty simple. 代码非常简单。 I use synchronous HTTP call form multiple threads: 我使用同步HTTP调用形式多个线程:

private final HttpClient httpClient = HttpClient.newBuilder()
        .executor(Utils.newFixedThreadPoolExecutor(1, "HttpClient"))
        .build();

private JsonObject useHttpClient(URL url, String params) throws Exception {
    HttpRequest req = HttpRequest.newBuilder()
            .uri(url.toURI())
            .setHeader("Connection", "keep-alive")
            .setHeader("Accept-Encoding", "gzip")
            .timeout(timeout)
            .POST(HttpRequest.BodyPublisher.fromString(params))
            .build();
    HttpResponse<InputStream> response = httpClient.send(req, HttpResponse.BodyHandler.asInputStream());
    if (response.statusCode() != 200) {
        throw new IOException("Server returned " + response.statusCode());
    }
    String encoding = response.headers().firstValue("content-encoding").orElse("");
    return parseResponseStream(encoding, response.body());
}

Sometimes I get NPEs: 有时我会得到NPE:

java.lang.NullPointerException: null
at jdk.incubator.http.internal.hpack.HeaderTable$Table.remove(HeaderTable.java:455) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.HeaderTable.evictEntry(HeaderTable.java:264) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.HeaderTable.put(HeaderTable.java:233) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.HeaderTable.put(HeaderTable.java:215) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.Decoder.resumeLiteralWithIndexing(Decoder.java:464) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.Decoder.proceed(Decoder.java:268) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.Decoder.decode(Decoder.java:246) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.decodeHeaders(Http2Connection.java:471) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.processFrame(Http2Connection.java:635) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.frame.FramesDecoder.decode(FramesDecoder.java:156) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection$FramesController.processReceivedData(Http2Connection.java:195) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.asyncReceive(Http2Connection.java:528) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection$Http2TubeSubscriber.processQueue(Http2Connection.java:1054) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147) ~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198) ~[jdk.incubator.httpclient:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [?:?]

Are there any problem in my code? 我的代码有问题吗? What can be reason for this exception? 这个例外的原因是什么?

C:\Program Files\Java\jdk-10\bin>java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

Are there any problem in my code? 我的代码有问题吗?

As someone familiar with the JDK HTTP Client API, I cannot see any specific issues with the code you posted. 作为熟悉JDK HTTP Client API的人,我看不到您发布的代码的任何特定问题。

What can be reason for this exception? 这个例外的原因是什么?

The reason for the exception is a bug in the JDK HTTP Client HPACK code. 异常的原因是JDK HTTP客户端HPACK代码中的错误。 There is nothing that you can do, in your code, to workaround it. 在代码中,您无法做任何事情来解决它。

Specific information on the JDK HPACK bug can be found at https://bugs.openjdk.java.net/browse/JDK-8200625 ( duplicating technical information, from the aforementioned OpenJDK JIRA issue, here will not add value, and likely to become stale quickly ) 有关JDK HPACK错误的具体信息可以在https://bugs.openjdk.java.net/browse/JDK-8200625上找到(复制技术信息,来自上述OpenJDK JIRA问题,这里不会增加价值,可能会变成快速陈旧)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM