From 92e2e1c36233426e8052c33c320ddbdf0c38248a Mon Sep 17 00:00:00 2001 From: Vasileios Chroniadis Date: Fri, 15 Mar 2019 16:25:06 +0000 Subject: [PATCH 1/4] 2.x: Improving NPE message in CompositeDisposable add(..) when param is null --- src/main/java/io/reactivex/disposables/CompositeDisposable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/disposables/CompositeDisposable.java b/src/main/java/io/reactivex/disposables/CompositeDisposable.java index 5bed43ec77..4296d38005 100644 --- a/src/main/java/io/reactivex/disposables/CompositeDisposable.java +++ b/src/main/java/io/reactivex/disposables/CompositeDisposable.java @@ -93,7 +93,7 @@ public boolean isDisposed() { */ @Override public boolean add(@NonNull Disposable d) { - ObjectHelper.requireNonNull(d, "d is null"); + ObjectHelper.requireNonNull(d, "Disposable item is null"); if (!disposed) { synchronized (this) { if (!disposed) { From a8737ab72840c5c33fa386bb0efbcd513dc34277 Mon Sep 17 00:00:00 2001 From: Vasileios Chroniadis Date: Fri, 15 Mar 2019 16:25:41 +0000 Subject: [PATCH 2/4] 2.x: Improving NPE message in CompositeDisposable addAll(..) when item in vararg param is null --- src/main/java/io/reactivex/disposables/CompositeDisposable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/disposables/CompositeDisposable.java b/src/main/java/io/reactivex/disposables/CompositeDisposable.java index 4296d38005..a390e1cc1d 100644 --- a/src/main/java/io/reactivex/disposables/CompositeDisposable.java +++ b/src/main/java/io/reactivex/disposables/CompositeDisposable.java @@ -128,7 +128,7 @@ public boolean addAll(@NonNull Disposable... ds) { resources = set; } for (Disposable d : ds) { - ObjectHelper.requireNonNull(d, "d is null"); + ObjectHelper.requireNonNull(d, "Disposable item is null"); set.add(d); } return true; From b216f5922b463da4eaf43e83aec3b3f520ad2901 Mon Sep 17 00:00:00 2001 From: Vasileios Chroniadis Date: Fri, 15 Mar 2019 16:47:23 +0000 Subject: [PATCH 3/4] 2.x: Improved in CompositeDisposable: NPE error messages, parameter naming at methods, added @throws javadoc where applicable --- .../disposables/CompositeDisposable.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/io/reactivex/disposables/CompositeDisposable.java b/src/main/java/io/reactivex/disposables/CompositeDisposable.java index a390e1cc1d..338cbceebd 100644 --- a/src/main/java/io/reactivex/disposables/CompositeDisposable.java +++ b/src/main/java/io/reactivex/disposables/CompositeDisposable.java @@ -38,26 +38,28 @@ public CompositeDisposable() { /** * Creates a CompositeDisposables with the given array of initial elements. - * @param resources the array of Disposables to start with + * @param disposables the array of Disposables to start with + * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null */ - public CompositeDisposable(@NonNull Disposable... resources) { - ObjectHelper.requireNonNull(resources, "resources is null"); - this.resources = new OpenHashSet(resources.length + 1); - for (Disposable d : resources) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + public CompositeDisposable(@NonNull Disposable... disposables) { + ObjectHelper.requireNonNull(disposables, "Disposables are null"); + this.resources = new OpenHashSet(disposables.length + 1); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); this.resources.add(d); } } /** * Creates a CompositeDisposables with the given Iterable sequence of initial elements. - * @param resources the Iterable sequence of Disposables to start with + * @param disposables the Iterable sequence of Disposables to start with + * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null */ - public CompositeDisposable(@NonNull Iterable resources) { - ObjectHelper.requireNonNull(resources, "resources is null"); + public CompositeDisposable(@NonNull Iterable disposables) { + ObjectHelper.requireNonNull(disposables, "Disposables are null"); this.resources = new OpenHashSet(); - for (Disposable d : resources) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); this.resources.add(d); } } @@ -88,12 +90,13 @@ public boolean isDisposed() { /** * Adds a disposable to this container or disposes it if the * container has been disposed. - * @param d the disposable to add, not null + * @param disposable the disposable to add, not null * @return true if successful, false if this container has been disposed + * @throws NullPointerException if disposable param is null */ @Override - public boolean add(@NonNull Disposable d) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + public boolean add(@NonNull Disposable disposable) { + ObjectHelper.requireNonNull(disposable, "Disposable item is null"); if (!disposed) { synchronized (this) { if (!disposed) { @@ -102,40 +105,41 @@ public boolean add(@NonNull Disposable d) { set = new OpenHashSet(); resources = set; } - set.add(d); + set.add(disposable); return true; } } } - d.dispose(); + disposable.dispose(); return false; } /** * Atomically adds the given array of Disposables to the container or * disposes them all if the container has been disposed. - * @param ds the array of Disposables + * @param disposables the array of Disposables * @return true if the operation was successful, false if the container has been disposed + * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null */ - public boolean addAll(@NonNull Disposable... ds) { - ObjectHelper.requireNonNull(ds, "ds is null"); + public boolean addAll(@NonNull Disposable... disposables) { + ObjectHelper.requireNonNull(disposables, "Disposables are null"); if (!disposed) { synchronized (this) { if (!disposed) { OpenHashSet set = resources; if (set == null) { - set = new OpenHashSet(ds.length + 1); + set = new OpenHashSet(disposables.length + 1); resources = set; } - for (Disposable d : ds) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + for (Disposable d : disposables) { + ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); set.add(d); } return true; } } } - for (Disposable d : ds) { + for (Disposable d : disposables) { d.dispose(); } return false; @@ -144,13 +148,13 @@ public boolean addAll(@NonNull Disposable... ds) { /** * Removes and disposes the given disposable if it is part of this * container. - * @param d the disposable to remove and dispose, not null + * @param disposable the disposable to remove and dispose, not null * @return true if the operation was successful */ @Override - public boolean remove(@NonNull Disposable d) { - if (delete(d)) { - d.dispose(); + public boolean remove(@NonNull Disposable disposable) { + if (delete(disposable)) { + disposable.dispose(); return true; } return false; @@ -159,12 +163,13 @@ public boolean remove(@NonNull Disposable d) { /** * Removes (but does not dispose) the given disposable if it is part of this * container. - * @param d the disposable to remove, not null + * @param disposable the disposable to remove, not null * @return true if the operation was successful + * @throws NullPointerException if disposable param is null */ @Override - public boolean delete(@NonNull Disposable d) { - ObjectHelper.requireNonNull(d, "Disposable item is null"); + public boolean delete(@NonNull Disposable disposable) { + ObjectHelper.requireNonNull(disposable, "Disposable item is null"); if (disposed) { return false; } @@ -174,7 +179,7 @@ public boolean delete(@NonNull Disposable d) { } OpenHashSet set = resources; - if (set == null || !set.remove(d)) { + if (set == null || !set.remove(disposable)) { return false; } } From e909e0854d4f3057a7377ee8bd6ef8a3fe07b873 Mon Sep 17 00:00:00 2001 From: Vasileios Chroniadis Date: Fri, 15 Mar 2019 17:28:26 +0000 Subject: [PATCH 4/4] 2.x: Applied PR suggestions in javadoc and messages for CompositeDisposable --- .../disposables/CompositeDisposable.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/reactivex/disposables/CompositeDisposable.java b/src/main/java/io/reactivex/disposables/CompositeDisposable.java index 338cbceebd..f7a1bf4a36 100644 --- a/src/main/java/io/reactivex/disposables/CompositeDisposable.java +++ b/src/main/java/io/reactivex/disposables/CompositeDisposable.java @@ -39,13 +39,13 @@ public CompositeDisposable() { /** * Creates a CompositeDisposables with the given array of initial elements. * @param disposables the array of Disposables to start with - * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null + * @throws NullPointerException if {@code disposables} or any of its array items is null */ public CompositeDisposable(@NonNull Disposable... disposables) { - ObjectHelper.requireNonNull(disposables, "Disposables are null"); + ObjectHelper.requireNonNull(disposables, "disposables is null"); this.resources = new OpenHashSet(disposables.length + 1); for (Disposable d : disposables) { - ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); + ObjectHelper.requireNonNull(d, "A Disposable in the disposables array is null"); this.resources.add(d); } } @@ -53,13 +53,13 @@ public CompositeDisposable(@NonNull Disposable... disposables) { /** * Creates a CompositeDisposables with the given Iterable sequence of initial elements. * @param disposables the Iterable sequence of Disposables to start with - * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null + * @throws NullPointerException if {@code disposables} or any of its items is null */ public CompositeDisposable(@NonNull Iterable disposables) { - ObjectHelper.requireNonNull(disposables, "Disposables are null"); + ObjectHelper.requireNonNull(disposables, "disposables is null"); this.resources = new OpenHashSet(); for (Disposable d : disposables) { - ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); + ObjectHelper.requireNonNull(d, "A Disposable item in the disposables sequence is null"); this.resources.add(d); } } @@ -92,11 +92,11 @@ public boolean isDisposed() { * container has been disposed. * @param disposable the disposable to add, not null * @return true if successful, false if this container has been disposed - * @throws NullPointerException if disposable param is null + * @throws NullPointerException if {@code disposable} is null */ @Override public boolean add(@NonNull Disposable disposable) { - ObjectHelper.requireNonNull(disposable, "Disposable item is null"); + ObjectHelper.requireNonNull(disposable, "disposable is null"); if (!disposed) { synchronized (this) { if (!disposed) { @@ -119,10 +119,10 @@ public boolean add(@NonNull Disposable disposable) { * disposes them all if the container has been disposed. * @param disposables the array of Disposables * @return true if the operation was successful, false if the container has been disposed - * @throws NullPointerException if disposables param is null, or a Disposable item in the disposables is null + * @throws NullPointerException if {@code disposables} or any of its array items is null */ public boolean addAll(@NonNull Disposable... disposables) { - ObjectHelper.requireNonNull(disposables, "Disposables are null"); + ObjectHelper.requireNonNull(disposables, "disposables is null"); if (!disposed) { synchronized (this) { if (!disposed) { @@ -132,7 +132,7 @@ public boolean addAll(@NonNull Disposable... disposables) { resources = set; } for (Disposable d : disposables) { - ObjectHelper.requireNonNull(d, "Disposable item in Disposables is null"); + ObjectHelper.requireNonNull(d, "A Disposable in the disposables array is null"); set.add(d); } return true; @@ -165,11 +165,11 @@ public boolean remove(@NonNull Disposable disposable) { * container. * @param disposable the disposable to remove, not null * @return true if the operation was successful - * @throws NullPointerException if disposable param is null + * @throws NullPointerException if {@code disposable} is null */ @Override public boolean delete(@NonNull Disposable disposable) { - ObjectHelper.requireNonNull(disposable, "Disposable item is null"); + ObjectHelper.requireNonNull(disposable, "disposables is null"); if (disposed) { return false; }