Skip to content

1.x: Add system property for disabling usage of Unsafe API #3829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/rx/internal/util/unsafe/UnsafeAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
/**
* All use of this class MUST first check that UnsafeAccess.isUnsafeAvailable() == true
* otherwise NPEs will happen in environments without "suc.misc.Unsafe" such as Android.
* <p>
* Note that you can force RxJava to not use Unsafe API by setting any value to System Property
* {@code rx.unsafe-disable}.
*/
public final class UnsafeAccess {
private UnsafeAccess() {
throw new IllegalStateException("No instances!");
}

public static final Unsafe UNSAFE;

private static final boolean DISABLED_BY_USER = System.getProperty("rx.unsafe-disable") != null;

static {
Unsafe u = null;
try {
Expand All @@ -48,7 +54,7 @@ private UnsafeAccess() {
}

public static boolean isUnsafeAvailable() {
return UNSAFE != null;
return UNSAFE != null && !DISABLED_BY_USER;
}

/*
Expand Down