diff --git a/core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtils.scala b/core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtils.scala index a62f1b9f9..822feb22f 100644 --- a/core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtils.scala +++ b/core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtils.scala @@ -19,6 +19,6 @@ object UnsafeUtils { }.getOrElse((null, 0L, 0L)) private[jsoniter_scala] final def getLatin1Array(s: String): Array[Byte] = - if (stringCoderOffset == 0 || unsafe.getByte(s, stringCoderOffset) != 0) null + if (stringCoderOffset == 0 || (s eq null) || unsafe.getByte(s, stringCoderOffset) != 0) null else unsafe.getObject(s, stringValueOffset).asInstanceOf[Array[Byte]] } diff --git a/core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtilsSpec.scala b/core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtilsSpec.scala new file mode 100644 index 000000000..c1eaaa6e9 --- /dev/null +++ b/core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtilsSpec.scala @@ -0,0 +1,12 @@ +package com.github.plokhotnyuk.jsoniter_scala.core + +import org.scalatest.{Matchers, WordSpec} + +class UnsafeUtilsSpec extends WordSpec with Matchers { + "UnsafeUtils" should { + "be safe when getLatin1Array is called" in { + UnsafeUtils.getLatin1Array("s") + UnsafeUtils.getLatin1Array(null) shouldBe null + } + } +}