lhotari commented on code in PR #25939:
URL: https://github.com/apache/pulsar/pull/25939#discussion_r3361095133
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -200,6 +200,20 @@ public static <T> CompletableFuture<T>
failedFuture(Throwable t) {
return future;
}
+ private static <T> CompletableFuture<T>
getFutureSafely(Supplier<CompletableFuture<T>> supplier,
+ String
nullFutureMessage) {
Review Comment:
This method could be made public after renaming and simplifying the
signature. It's an overkill to add a separate message for the
NullPointerException.
```suggestion
public static <T> CompletableFuture<T>
supplySafely(Supplier<CompletableFuture<T>> supplier) {
```
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -200,6 +200,20 @@ public static <T> CompletableFuture<T>
failedFuture(Throwable t) {
return future;
}
+ private static <T> CompletableFuture<T>
getFutureSafely(Supplier<CompletableFuture<T>> supplier,
+ String
nullFutureMessage) {
+ CompletableFuture<T> future;
+ try {
+ future = supplier.get();
+ } catch (Throwable t) {
+ return failedFuture(t);
+ }
+ if (future == null) {
+ return failedFuture(new NullPointerException(nullFutureMessage));
Review Comment:
Instead of using an explicity NPE message, something like this would be
cover what is needed.
```suggestion
return failedFuture(new NullPointerException("The given supplier
returned null, supplier=" + supplier));
```
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -200,6 +200,20 @@ public static <T> CompletableFuture<T>
failedFuture(Throwable t) {
return future;
}
+ private static <T> CompletableFuture<T>
getFutureSafely(Supplier<CompletableFuture<T>> supplier,
+ String
nullFutureMessage) {
Review Comment:
while making this `public`, add proper javadoc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]