fixed crashing when removing mods
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright 2013 Netflix, Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -21,19 +21,22 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import rx.Subscription;
|
||||
|
||||
/**
|
||||
* Thread-safe wrapper around Observable Subscription that ensures unsubscribe can be called only once.
|
||||
* Thread-safe wrapper around Observable Subscription that ensures unsubscribe
|
||||
* can be called only once.
|
||||
* <p>
|
||||
* Also used to:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>allow the AtomicObserver to have access to the subscription in asynchronous execution for checking if unsubscribed occurred without onComplete/onError.</li>
|
||||
* <li>allow the AtomicObserver to have access to the subscription in
|
||||
* asynchronous execution for checking if unsubscribed occurred without
|
||||
* onComplete/onError.</li>
|
||||
* <li>handle both synchronous and asynchronous subscribe() execution flows</li>
|
||||
* </ul>
|
||||
*/
|
||||
public final class AtomicObservableSubscription implements Subscription {
|
||||
|
||||
private AtomicReference<Subscription> actualSubscription = new AtomicReference<Subscription>();
|
||||
private AtomicBoolean unsubscribed = new AtomicBoolean(false);
|
||||
private final AtomicReference<Subscription> actualSubscription = new AtomicReference<>();
|
||||
private final AtomicBoolean unsubscribed = new AtomicBoolean(false);
|
||||
|
||||
public AtomicObservableSubscription() {
|
||||
|
||||
@@ -44,16 +47,16 @@ public final class AtomicObservableSubscription implements Subscription {
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the actual subscription once it exists (if it wasn't available when constructed)
|
||||
*
|
||||
* Wraps the actual subscription once it exists (if it wasn't available when
|
||||
* constructed)
|
||||
*
|
||||
* @param actualSubscription
|
||||
* @throws IllegalStateException
|
||||
* if trying to set more than once (or use this method after setting via constructor)
|
||||
* @throws IllegalStateException if trying to set more than once (or use
|
||||
* this method after setting via constructor)
|
||||
*/
|
||||
public AtomicObservableSubscription wrap(Subscription actualSubscription) {
|
||||
if (!this.actualSubscription.compareAndSet(null, actualSubscription)) {
|
||||
if (!this.actualSubscription.compareAndSet(null, actualSubscription))
|
||||
throw new IllegalStateException("Can not set subscription more than once.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright 2013 Netflix, Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -23,7 +23,8 @@ import java.util.List;
|
||||
/**
|
||||
* Exception that is a composite of 1 or more other exceptions.
|
||||
* <p>
|
||||
* The <code>getMessage()</code> will return a concatenation of the composite exceptions.
|
||||
* The <code>getMessage()</code> will return a concatenation of the composite
|
||||
* exceptions.
|
||||
*/
|
||||
public class CompositeException extends RuntimeException {
|
||||
|
||||
@@ -34,16 +35,14 @@ public class CompositeException extends RuntimeException {
|
||||
|
||||
public CompositeException(String messagePrefix, Collection<Exception> errors) {
|
||||
StringBuilder _message = new StringBuilder();
|
||||
if (messagePrefix != null) {
|
||||
if (messagePrefix != null)
|
||||
_message.append(messagePrefix).append(" => ");
|
||||
}
|
||||
|
||||
List<Exception> _exceptions = new ArrayList<Exception>();
|
||||
List<Exception> _exceptions = new ArrayList<>();
|
||||
for (Exception e : errors) {
|
||||
_exceptions.add(e);
|
||||
if (_message.length() > 0) {
|
||||
if (_message.length() > 0)
|
||||
_message.append(", ");
|
||||
}
|
||||
_message.append(e.getClass().getSimpleName()).append(":").append(e.getMessage());
|
||||
}
|
||||
this.exceptions = Collections.unmodifiableList(_exceptions);
|
||||
@@ -62,4 +61,4 @@ public class CompositeException extends RuntimeException {
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user