Skip to content

Commit f7d23ae

Browse files
committed
Merge pull request #3829 from artem-zinnatullin/unsafe-enable-disable-system-property
1.x: Add system property for disabling usage of Unsafe API
2 parents e971c4a + 3e2dd9e commit f7d23ae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/rx/internal/util/unsafe/UnsafeAccess.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@
2222
/**
2323
* All use of this class MUST first check that UnsafeAccess.isUnsafeAvailable() == true
2424
* otherwise NPEs will happen in environments without "suc.misc.Unsafe" such as Android.
25+
* <p>
26+
* Note that you can force RxJava to not use Unsafe API by setting any value to System Property
27+
* {@code rx.unsafe-disable}.
2528
*/
2629
public final class UnsafeAccess {
2730
private UnsafeAccess() {
2831
throw new IllegalStateException("No instances!");
2932
}
3033

3134
public static final Unsafe UNSAFE;
35+
36+
private static final boolean DISABLED_BY_USER = System.getProperty("rx.unsafe-disable") != null;
37+
3238
static {
3339
Unsafe u = null;
3440
try {
@@ -48,7 +54,7 @@ private UnsafeAccess() {
4854
}
4955

5056
public static boolean isUnsafeAvailable() {
51-
return UNSAFE != null;
57+
return UNSAFE != null && !DISABLED_BY_USER;
5258
}
5359

5460
/*

0 commit comments

Comments
 (0)