From 4d7bf227deefe79b349eb2ec2183a7c54d03655f Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Sat, 24 Feb 2018 12:51:04 +0100 Subject: [PATCH] Fix of JVM crush with JDK 9 --- .../jsoniter_scala/core/UnsafeUtils.scala | 2 +- .../jsoniter_scala/core/UnsafeUtilsSpec.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtilsSpec.scala 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 + } + } +}