Skip to content

Commit cce61d9

Browse files
committed
Fix # by removing importing of sun.misc.Unsafe and assessing to it only in a try/catch block
1 parent ab1bd5e commit cce61d9

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/UnsafeUtils.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.github.plokhotnyuk.jsoniter_scala.core
22

3-
import sun.misc.Unsafe
4-
53
import scala.util.Try
64

75
// FIXME: remove when perf. degradation of String.charAt when iterating through strings will be fixed in JDK 9:
86
// https://bugs.openjdk.java.net/browse/JDK-8013655
97
object UnsafeUtils {
108
private[this] final val (unsafe, stringValueOffset, stringCoderOffset) = Try {
119
val u = {
12-
val unsafeField = classOf[Unsafe].getDeclaredField("theUnsafe")
10+
val unsafeClass = classOf[sun.misc.Unsafe]
11+
val unsafeField = unsafeClass.getDeclaredField("theUnsafe")
1312
unsafeField.setAccessible(true)
14-
unsafeField.get(null).asInstanceOf[Unsafe]
13+
unsafeClass.cast(unsafeField.get(null))
1514
}
1615
(u,
1716
u.objectFieldOffset(classOf[String].getDeclaredField("value")),

core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UserAPI.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object UserAPI {
2424

2525
def encodeValue(x: User, out: JsonWriter): Unit = e0(x, out)
2626

27-
private def d2(in: JsonReader, default: Device): Device =
27+
private def d2(in: JsonReader, default: Device): Device =
2828
if (in.isNextToken('{')) {
2929
var _id: Int = 0
3030
var _model: String = null
@@ -34,7 +34,7 @@ object UserAPI {
3434
do {
3535
val l = in.readKeyAsCharBuf()
3636
(in.charBufToHashCode(l): @switch) match {
37-
case 3355 =>
37+
case 3355 =>
3838
if (in.isCharBufEqualsTo(l, "id")) {
3939
_id = in.readInt()
4040
req0 &= -2
@@ -53,7 +53,7 @@ object UserAPI {
5353
new Device(id = _id, model = _model)
5454
} else in.readNullOrTokenError(default, '{')
5555

56-
private def d1(in: JsonReader, default: Seq[Device]): Seq[Device] =
56+
private def d1(in: JsonReader, default: Seq[Device]): Seq[Device] =
5757
if (in.isNextToken('[')) {
5858
if (in.isNextToken(']')) default
5959
else {
@@ -66,7 +66,7 @@ object UserAPI {
6666
}
6767
} else in.readNullOrTokenError(default, '[')
6868

69-
private def d0(in: JsonReader, default: User): User =
69+
private def d0(in: JsonReader, default: User): User =
7070
if (in.isNextToken('{')) {
7171
var _name: String = null
7272
var _devices: Seq[Device] = Seq.empty[Device]

macros/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ object JsonCodecMaker {
385385
if (collisions.nonEmpty) {
386386
val formattedCollisions = collisions.mkString("'", "', '", "'")
387387
fail(s"Duplicated values defined for '$discriminatorFieldName': $formattedCollisions. " +
388-
s"Values returned by 'config.adtLeafClassNameMapper' should not match.")
388+
"Values returned by 'config.adtLeafClassNameMapper' should not match.")
389389
}
390390
}
391391

0 commit comments

Comments
 (0)