Skip to content

Commit 5be3a4b

Browse files
authored
1.x: apply fixes based on PMD suggestions (ReactiveX#4091)
* 1.x: apply fixes based on PMD suggestions * InternalError(Throwable cause) is not available * Remove private from inner (static) classes, add final where needed * Remove by akarnokd, update rules
1 parent afe3cb0 commit 5be3a4b

File tree

162 files changed

+1040
-1013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1040
-1013
lines changed

pmd.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
<rule ref="rulesets/java/basic.xml/DontUseFloatTypeForLoopIndices"/>
7272
<rule ref="rulesets/java/basic.xml/DoubleCheckedLocking"/>
7373
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
74-
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock"/>
7574
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer"/>
7675
<rule ref="rulesets/java/empty.xml/EmptyFinallyBlock"/>
7776
<rule ref="rulesets/java/empty.xml/EmptyInitializer"/>
@@ -134,9 +133,6 @@
134133
<rule ref="rulesets/java/javabeans.xml/MissingSerialVersionUID"/>
135134
<rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass"/>
136135
<rule ref="rulesets/java/logging-java.xml/MoreThanOneLogger"/>
137-
<rule ref="rulesets/java/codesize.xml/NcssConstructorCount"/>
138-
<rule ref="rulesets/java/codesize.xml/NcssMethodCount"/>
139-
<rule ref="rulesets/java/codesize.xml/NcssTypeCount"/>
140136
<rule ref="rulesets/java/naming.xml/NoPackage"/>
141137
<rule ref="rulesets/java/design.xml/NonCaseLabelInSwitchStatement"/>
142138
<rule ref="rulesets/java/design.xml/NonStaticInitializer"/>
@@ -160,7 +156,6 @@
160156
<rule ref="rulesets/java/design.xml/ReturnEmptyArrayRatherThanNull"/>
161157
<rule ref="rulesets/java/basic.xml/ReturnFromFinallyBlock"/>
162158
<rule ref="rulesets/java/migrating.xml/ShortInstantiation"/>
163-
<rule ref="rulesets/java/naming.xml/ShortMethodName"/>
164159
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException"/>
165160
<rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"/>
166161
<rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"/>
@@ -183,8 +178,6 @@
183178
<rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"/>
184179
<rule ref="rulesets/java/design.xml/TooFewBranchesForASwitchStatement"/>
185180
<rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
186-
<rule ref="rulesets/java/design.xml/UncommentedEmptyConstructor"/>
187-
<rule ref="rulesets/java/design.xml/UncommentedEmptyMethodBody"/>
188181
<rule ref="rulesets/java/basic.xml/UnconditionalIfStatement"/>
189182
<rule ref="rulesets/java/junit.xml/UnnecessaryBooleanAssertion"/>
190183
<rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange"/>

src/main/java/rx/BackpressureOverflow.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@
2424
@Experimental
2525
public final class BackpressureOverflow {
2626

27+
/**
28+
* Signal a MissingBackressureException due to lack of requests.
29+
*/
30+
public static final BackpressureOverflow.Strategy ON_OVERFLOW_ERROR = Error.INSTANCE;
31+
32+
/**
33+
* By default, signal a MissingBackressureException due to lack of requests.
34+
*/
35+
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DEFAULT = ON_OVERFLOW_ERROR;
36+
37+
/**
38+
* Drop the oldest value in the buffer.
39+
*/
40+
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DROP_OLDEST = DropOldest.INSTANCE;
41+
42+
/**
43+
* Drop the latest value.
44+
*/
45+
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DROP_LATEST = DropLatest.INSTANCE;
46+
47+
/**
48+
* Represents a callback called when a value is about to be dropped
49+
* due to lack of downstream requests.
50+
*/
2751
public interface Strategy {
2852

2953
/**
@@ -36,14 +60,6 @@ public interface Strategy {
3660
boolean mayAttemptDrop() throws MissingBackpressureException;
3761
}
3862

39-
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DEFAULT = Error.INSTANCE;
40-
41-
public static final BackpressureOverflow.Strategy ON_OVERFLOW_ERROR = Error.INSTANCE;
42-
43-
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DROP_OLDEST = DropOldest.INSTANCE;
44-
45-
public static final BackpressureOverflow.Strategy ON_OVERFLOW_DROP_LATEST = DropLatest.INSTANCE;
46-
4763
/**
4864
* Drop oldest items from the buffer making room for newer ones.
4965
*/

src/main/java/rx/Completable.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
*/
3939
@Experimental
4040
public class Completable {
41+
/** The actual subscription action. */
42+
private final CompletableOnSubscribe onSubscribe;
4143
/**
4244
* Callback used for building deferred computations that takes a CompletableSubscriber.
4345
*/
@@ -192,6 +194,22 @@ public void call(final CompletableSubscriber s) {
192194
final CompositeSubscription set = new CompositeSubscription();
193195
s.onSubscribe(set);
194196

197+
Iterator<? extends Completable> it;
198+
199+
try {
200+
it = sources.iterator();
201+
} catch (Throwable e) {
202+
s.onError(e);
203+
return;
204+
}
205+
206+
if (it == null) {
207+
s.onError(new NullPointerException("The iterator returned is null"));
208+
return;
209+
}
210+
211+
boolean empty = true;
212+
195213
final AtomicBoolean once = new AtomicBoolean();
196214

197215
CompletableSubscriber inner = new CompletableSubscriber() {
@@ -220,22 +238,6 @@ public void onSubscribe(Subscription d) {
220238

221239
};
222240

223-
Iterator<? extends Completable> it;
224-
225-
try {
226-
it = sources.iterator();
227-
} catch (Throwable e) {
228-
s.onError(e);
229-
return;
230-
}
231-
232-
if (it == null) {
233-
s.onError(new NullPointerException("The iterator returned is null"));
234-
return;
235-
}
236-
237-
boolean empty = true;
238-
239241
for (;;) {
240242
if (once.get() || set.isUnsubscribed()) {
241243
return;
@@ -377,7 +379,7 @@ public static Completable create(CompletableOnSubscribe onSubscribe) {
377379
requireNonNull(onSubscribe);
378380
try {
379381
return new Completable(onSubscribe);
380-
} catch (NullPointerException ex) {
382+
} catch (NullPointerException ex) { // NOPMD
381383
throw ex;
382384
} catch (Throwable ex) {
383385
RxJavaHooks.onError(ex);
@@ -849,7 +851,7 @@ public static <R> Completable using(final Func0<R> resourceFunc0,
849851
return create(new CompletableOnSubscribe() {
850852
@Override
851853
public void call(final CompletableSubscriber s) {
852-
final R resource;
854+
final R resource; // NOPMD
853855

854856
try {
855857
resource = resourceFunc0.call();
@@ -965,9 +967,6 @@ public void call() {
965967
});
966968
}
967969

968-
/** The actual subscription action. */
969-
private final CompletableOnSubscribe onSubscribe;
970-
971970
/**
972971
* Constructs a Completable instance with the given onSubscribe callback.
973972
* @param onSubscribe the callback that will receive CompletableSubscribers when they subscribe,
@@ -1550,7 +1549,7 @@ public void call(CompletableSubscriber s) {
15501549
CompletableSubscriber sw = onLiftDecorated.call(s);
15511550

15521551
unsafeSubscribe(sw);
1553-
} catch (NullPointerException ex) {
1552+
} catch (NullPointerException ex) { // NOPMD
15541553
throw ex;
15551554
} catch (Throwable ex) {
15561555
throw toNpe(ex);
@@ -2008,7 +2007,7 @@ public final void unsafeSubscribe(CompletableSubscriber s) {
20082007
CompletableOnSubscribe onSubscribeDecorated = RxJavaHooks.onCompletableStart(this, this.onSubscribe);
20092008

20102009
onSubscribeDecorated.call(s);
2011-
} catch (NullPointerException ex) {
2010+
} catch (NullPointerException ex) { // NOPMD
20122011
throw ex;
20132012
} catch (Throwable ex) {
20142013
Exceptions.throwIfFatal(ex);
@@ -2072,7 +2071,7 @@ public void onSubscribe(Subscription d) {
20722071
}
20732072
});
20742073
RxJavaHooks.onObservableReturn(s);
2075-
} catch (NullPointerException ex) {
2074+
} catch (NullPointerException ex) { // NOPMD
20762075
throw ex;
20772076
} catch (Throwable ex) {
20782077
Exceptions.throwIfFatal(ex);

src/main/java/rx/Notification.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,27 @@ public enum Kind {
182182

183183
@Override
184184
public String toString() {
185-
StringBuilder str = new StringBuilder("[").append(super.toString()).append(" ").append(getKind());
186-
if (hasValue())
187-
str.append(" ").append(getValue());
188-
if (hasThrowable())
189-
str.append(" ").append(getThrowable().getMessage());
190-
str.append("]");
185+
StringBuilder str = new StringBuilder(64).append('[').append(super.toString())
186+
.append(' ').append(getKind());
187+
if (hasValue()) {
188+
str.append(' ').append(getValue());
189+
}
190+
if (hasThrowable()) {
191+
str.append(' ').append(getThrowable().getMessage());
192+
}
193+
str.append(']');
191194
return str.toString();
192195
}
193196

194197
@Override
195198
public int hashCode() {
196199
int hash = getKind().hashCode();
197-
if (hasValue())
200+
if (hasValue()) {
198201
hash = hash * 31 + getValue().hashCode();
199-
if (hasThrowable())
202+
}
203+
if (hasThrowable()) {
200204
hash = hash * 31 + getThrowable().hashCode();
205+
}
201206
return hash;
202207
}
203208

@@ -224,10 +229,6 @@ public boolean equals(Object obj) {
224229
return false;
225230
}
226231

227-
if (!(throwable == notification.throwable || (throwable != null && throwable.equals(notification.throwable)))) {
228-
return false;
229-
}
230-
231-
return true;
232+
return (throwable == notification.throwable || (throwable != null && throwable.equals(notification.throwable)));
232233
}
233234
}

src/main/java/rx/Observable.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9015,7 +9015,7 @@ public final Subscription unsafeSubscribe(Subscriber<? super T> subscriber) {
90159015
// TODO could the hook be the cause of the error in the on error handling.
90169016
RxJavaHooks.onObservableError(r);
90179017
// TODO why aren't we throwing the hook's return value.
9018-
throw r;
9018+
throw r; // NOPMD
90199019
}
90209020
return Subscriptions.unsubscribed();
90219021
}
@@ -9112,7 +9112,7 @@ static <T> Subscription subscribe(Subscriber<? super T> subscriber, Observable<T
91129112
// TODO could the hook be the cause of the error in the on error handling.
91139113
RxJavaHooks.onObservableError(r);
91149114
// TODO why aren't we throwing the hook's return value.
9115-
throw r;
9115+
throw r; // NOPMD
91169116
}
91179117
}
91189118
return Subscriptions.unsubscribed();
@@ -9306,12 +9306,13 @@ public final Observable<T> takeFirst(Func1<? super T, Boolean> predicate) {
93069306
* @see <a href="http://reactivex.io/documentation/operators/takelast.html">ReactiveX operators documentation: TakeLast</a>
93079307
*/
93089308
public final Observable<T> takeLast(final int count) {
9309-
if (count == 0)
9309+
if (count == 0) {
93109310
return ignoreElements();
9311-
else if (count == 1 )
9311+
} else if (count == 1) {
93129312
return lift(OperatorTakeLastOne.<T>instance());
9313-
else
9313+
} else {
93149314
return lift(new OperatorTakeLast<T>(count));
9315+
}
93159316
}
93169317

93179318
/**

src/main/java/rx/Single.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ public static <T> Single<T> fromCallable(final Callable<? extends T> func) {
619619
return create(new OnSubscribe<T>() {
620620
@Override
621621
public void call(SingleSubscriber<? super T> singleSubscriber) {
622-
final T value;
622+
T value;
623623

624624
try {
625625
value = func.call();
@@ -1719,7 +1719,7 @@ public final Subscription unsafeSubscribe(Subscriber<? super T> subscriber) {
17191719
// TODO could the hook be the cause of the error in the on error handling.
17201720
RxJavaHooks.onSingleError(r);
17211721
// TODO why aren't we throwing the hook's return value.
1722-
throw r;
1722+
throw r; // NOPMD
17231723
}
17241724
return Subscriptions.unsubscribed();
17251725
}
@@ -1829,7 +1829,7 @@ public final Subscription subscribe(Subscriber<? super T> subscriber) {
18291829
// TODO could the hook be the cause of the error in the on error handling.
18301830
RxJavaHooks.onSingleError(r);
18311831
// TODO why aren't we throwing the hook's return value.
1832-
throw r;
1832+
throw r; // NOPMD
18331833
}
18341834
return Subscriptions.empty();
18351835
}
@@ -1875,7 +1875,7 @@ public final Subscription subscribe(final SingleSubscriber<? super T> te) {
18751875

18761876
@Override
18771877
public void onCompleted() {
1878-
1878+
// deliberately ignored
18791879
}
18801880

18811881
@Override
@@ -2376,6 +2376,7 @@ public final Single<T> doOnError(final Action1<Throwable> onError) {
23762376
Observer<T> observer = new Observer<T>() {
23772377
@Override
23782378
public void onCompleted() {
2379+
// deliberately ignored
23792380
}
23802381

23812382
@Override
@@ -2385,6 +2386,7 @@ public void onError(Throwable e) {
23852386

23862387
@Override
23872388
public void onNext(T t) {
2389+
// deliberately ignored
23882390
}
23892391
};
23902392

@@ -2410,10 +2412,12 @@ public final Single<T> doOnSuccess(final Action1<? super T> onSuccess) {
24102412
Observer<T> observer = new Observer<T>() {
24112413
@Override
24122414
public void onCompleted() {
2415+
// deliberately ignored
24132416
}
24142417

24152418
@Override
24162419
public void onError(Throwable e) {
2420+
// deliberately ignored
24172421
}
24182422

24192423
@Override
@@ -2589,7 +2593,7 @@ public final Single<T> doAfterTerminate(Action0 action) {
25892593
*/
25902594
@SuppressWarnings("unchecked")
25912595
static <T> Single<? extends T>[] iterableToArray(final Iterable<? extends Single<? extends T>> singlesIterable) {
2592-
final Single<? extends T>[] singlesArray;
2596+
Single<? extends T>[] singlesArray;
25932597
int count;
25942598

25952599
if (singlesIterable instanceof Collection) {

src/main/java/rx/exceptions/AssemblyStackTraceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AssemblyStackTraceException(String message) {
4646
}
4747

4848
@Override
49-
public synchronized Throwable fillInStackTrace() {
49+
public synchronized Throwable fillInStackTrace() { // NOPMD
5050
return this;
5151
}
5252
}

0 commit comments

Comments
 (0)