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
1.x: Plugin lookup workaround for System.properties access restrictions #5820
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ public void reset() { | |
public RxJavaErrorHandler getErrorHandler() { | ||
if (errorHandler.get() == null) { | ||
// check for an implementation from System.getProperty first | ||
Object impl = getPluginImplementationViaProperty(RxJavaErrorHandler.class, System.getProperties()); | ||
Object impl = getPluginImplementationViaProperty(RxJavaErrorHandler.class, getSystemPropertiesSafe()); | ||
if (impl == null) { | ||
// nothing set via properties so initialize with default | ||
errorHandler.compareAndSet(null, DEFAULT_ERROR_HANDLER); | ||
|
@@ -147,7 +147,7 @@ public void registerErrorHandler(RxJavaErrorHandler impl) { | |
public RxJavaObservableExecutionHook getObservableExecutionHook() { | ||
if (observableExecutionHook.get() == null) { | ||
// check for an implementation from System.getProperty first | ||
Object impl = getPluginImplementationViaProperty(RxJavaObservableExecutionHook.class, System.getProperties()); | ||
Object impl = getPluginImplementationViaProperty(RxJavaObservableExecutionHook.class, getSystemPropertiesSafe()); | ||
if (impl == null) { | ||
// nothing set via properties so initialize with default | ||
observableExecutionHook.compareAndSet(null, RxJavaObservableExecutionHookDefault.getInstance()); | ||
|
@@ -189,7 +189,7 @@ public void registerObservableExecutionHook(RxJavaObservableExecutionHook impl) | |
public RxJavaSingleExecutionHook getSingleExecutionHook() { | ||
if (singleExecutionHook.get() == null) { | ||
// check for an implementation from System.getProperty first | ||
Object impl = getPluginImplementationViaProperty(RxJavaSingleExecutionHook.class, System.getProperties()); | ||
Object impl = getPluginImplementationViaProperty(RxJavaSingleExecutionHook.class, getSystemPropertiesSafe()); | ||
if (impl == null) { | ||
// nothing set via properties so initialize with default | ||
singleExecutionHook.compareAndSet(null, RxJavaSingleExecutionHookDefault.getInstance()); | ||
|
@@ -232,7 +232,7 @@ public void registerSingleExecutionHook(RxJavaSingleExecutionHook impl) { | |
public RxJavaCompletableExecutionHook getCompletableExecutionHook() { | ||
if (completableExecutionHook.get() == null) { | ||
// check for an implementation from System.getProperty first | ||
Object impl = getPluginImplementationViaProperty(RxJavaCompletableExecutionHook.class, System.getProperties()); | ||
Object impl = getPluginImplementationViaProperty(RxJavaCompletableExecutionHook.class, getSystemPropertiesSafe()); | ||
if (impl == null) { | ||
// nothing set via properties so initialize with default | ||
completableExecutionHook.compareAndSet(null, new RxJavaCompletableExecutionHook() { }); | ||
|
@@ -262,6 +262,19 @@ public void registerCompletableExecutionHook(RxJavaCompletableExecutionHook impl | |
} | ||
} | ||
|
||
/** | ||
* A security manager may prevent accessing the System properties entirely, | ||
* therefore, the SecurityException is turned into an empty properties. | ||
* @return the Properties to use for looking up settings | ||
*/ | ||
/* test */ static Properties getSystemPropertiesSafe() { | ||
try { | ||
return System.getProperties(); | ||
} catch (SecurityException ex) { | ||
return new Properties(); | ||
} | ||
} | ||
|
||
/* test */ static Object getPluginImplementationViaProperty(Class<?> pluginClass, Properties propsIn) { | ||
// Make a defensive clone because traversal may fail with ConcurrentModificationException | ||
// if the properties get changed by something outside RxJava. | ||
|
@@ -284,25 +297,32 @@ public void registerCompletableExecutionHook(RxJavaCompletableExecutionHook impl | |
String classSuffix = ".class"; | ||
String implSuffix = ".impl"; | ||
|
||
for (Map.Entry<Object, Object> e : props.entrySet()) { | ||
String key = e.getKey().toString(); | ||
if (key.startsWith(pluginPrefix) && key.endsWith(classSuffix)) { | ||
String value = e.getValue().toString(); | ||
try { | ||
for (Map.Entry<Object, Object> e : props.entrySet()) { | ||
String key = e.getKey().toString(); | ||
if (key.startsWith(pluginPrefix) && key.endsWith(classSuffix)) { | ||
String value = e.getValue().toString(); | ||
|
||
if (classSimpleName.equals(value)) { | ||
String index = key.substring(0, key.length() - classSuffix.length()).substring(pluginPrefix.length()); | ||
|
||
if (classSimpleName.equals(value)) { | ||
String index = key.substring(0, key.length() - classSuffix.length()).substring(pluginPrefix.length()); | ||
String implKey = pluginPrefix + index + implSuffix; | ||
|
||
String implKey = pluginPrefix + index + implSuffix; | ||
implementingClass = props.getProperty(implKey); | ||
|
||
implementingClass = props.getProperty(implKey); | ||
if (implementingClass == null) { | ||
throw new IllegalStateException("Implementing class declaration for " + classSimpleName + " missing: " + implKey); | ||
} | ||
|
||
if (implementingClass == null) { | ||
throw new IllegalStateException("Implementing class declaration for " + classSimpleName + " missing: " + implKey); | ||
break; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} catch (SecurityException ex) { | ||
// https://github.com/ReactiveX/RxJava/issues/5819 | ||
// We don't seem to have access to all properties. | ||
// At least print the exception to the console. | ||
ex.printStackTrace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call RxJavaPlugins.onError() or however that api is called in 1.x? I believe people won't like stacktrace popping up in their logs without ability to swallow it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't call that because this is part of the initialization process of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mhm, I see, ok |
||
} | ||
} | ||
|
||
|
@@ -339,7 +359,7 @@ public void registerCompletableExecutionHook(RxJavaCompletableExecutionHook impl | |
public RxJavaSchedulersHook getSchedulersHook() { | ||
if (schedulersHook.get() == null) { | ||
// check for an implementation from System.getProperty first | ||
Object impl = getPluginImplementationViaProperty(RxJavaSchedulersHook.class, System.getProperties()); | ||
Object impl = getPluginImplementationViaProperty(RxJavaSchedulersHook.class, getSystemPropertiesSafe()); | ||
if (impl == null) { | ||
// nothing set via properties so initialize with default | ||
schedulersHook.compareAndSet(null, RxJavaSchedulersHook.getDefaultInstance()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "test"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It indicates the method is
package private
for testing purposes instead ofprivate
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's consistent with the other methods. ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, haven't seen these in a while, my bad