Skip to content

Commit

Permalink
Fixing issue #2545, NullPointerException in JavaClient:42 getting con…
Browse files Browse the repository at this point in the history
…tent charset from entity (#2546)
  • Loading branch information
longliveenduro committed Oct 22, 2021
1 parent 5c562b7 commit c7f2532
Showing 1 changed file with 4 additions and 3 deletions.
@@ -1,9 +1,8 @@
package com.sksamuel.elastic4s.http

import java.io.InputStream
import java.nio.charset.Charset
import java.nio.charset.{Charset, StandardCharsets}
import java.util.zip.GZIPInputStream

import com.sksamuel.elastic4s.{ElasticNodeEndpoint, ElasticProperties, ElasticRequest, HttpClient, HttpEntity, HttpResponse, Show}
import com.sksamuel.exts.Logging
import org.apache.http.HttpHost
Expand Down Expand Up @@ -39,7 +38,9 @@ class JavaClient(client: RestClient) extends HttpClient {

def fromResponse(r: org.elasticsearch.client.Response): HttpResponse = {
val entity = Option(r.getEntity).map { entity =>
val contentCharset = Option(ContentType.get(entity)).fold(Charset.forName("UTF-8"))(_.getCharset)
val contentCharset = Option(
Option(ContentType.get(entity)).fold(StandardCharsets.UTF_8)(_.getCharset)
).getOrElse(StandardCharsets.UTF_8)
implicit val codec: Codec = Codec(contentCharset)

val contentStream: InputStream = {
Expand Down

0 comments on commit c7f2532

Please sign in to comment.