Skip to content

Commit

Permalink
Added the system property "kryo.unsafe" to disable accessing Unsafe.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Feb 12, 2019
1 parent b97ab90 commit 83b3d11
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/com/esotericsoftware/kryo/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@
public class Util {
static public final boolean isAndroid = "Dalvik".equals(System.getProperty("java.vm.name"));

/** True if Unsafe is available. */
/** True if Unsafe is available. Unsafe can be disabled by setting the system property "kryo.unsafe" to "false". */
static public final boolean unsafe;
static {
boolean found = false;
try {
found = Class.forName("com.esotericsoftware.kryo.unsafe.UnsafeUtil", true, FieldSerializer.class.getClassLoader())
.getField("unsafe").get(null) != null;
} catch (Throwable ex) {
if (TRACE) trace("kryo", "Unsafe is unavailable.", ex);
if ("false".equals(System.getProperty("kryo.unsafe"))) {
if (TRACE) trace("kryo", "Unsafe is disabled.");
} else {
try {
found = Class.forName("com.esotericsoftware.kryo.unsafe.UnsafeUtil", true, FieldSerializer.class.getClassLoader())
.getField("unsafe").get(null) != null;
} catch (Throwable ex) {
if (TRACE) trace("kryo", "Unsafe is unavailable.", ex);
}
}
unsafe = found;
}
Expand Down

0 comments on commit 83b3d11

Please sign in to comment.