cyclops icon indicating copy to clipboard operation
cyclops copied to clipboard

Possible Nullpointers in capture(..) of missing cause in InterruptedException

Open schoberwirt opened this issue 10 years ago • 3 comments

In the safeGet(..) method in BlockingStreamHelper catches an InterruptedException, that is thrown by CompletableFuture.get(..) This Exception has getCause()==null in it's current implementation of the CompletableFuture.

With this, the capture(..) method in BlockingStreamHelper seems quirky.

static void capture(final Exception e,Optional<Consumer<Throwable>> errorHandler) {
        errorHandler.ifPresent((handler) -> {
            if (!(e.getCause() instanceof FilteredExecutionPathException)) {
                handler.accept(e.getCause());
            }
        });
    }
  1. !(null instanceof FilteredExecutionPathException) will probably always be true
  2. handler.accept(e.getCause()) is a code smell for a downstream up NullpointerException

In it's current implementation, the default errorHandler is SLF4J's log.error(..). The example I'm working with never reaches this bit of code.

Here's the interesting part of the stacktrace and our corresponding code:

//the list has been created before
private Consumer<Throwable> captureError(List<Exception> errors) {
        return e -> {
            log.debug("Capturing error {}", e);
            errors.add((Exception) (e.getCause() == null ? e : e.getCause()));
        };
    }

When this code is called, e is already null.

java.lang.NullPointerException: null at ourcompany.reactive.Reactive.lambda$captureError$8(Reactive.java:146) ~[company-library-X.X.0-SNAPSHOT.jar!/:na] at com.aol.cyclops.types.futurestream.BlockingStreamHelper.lambda$capture$6(BlockingStreamHelper.java:52) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2] at java.util.Optional.ifPresent(Optional.java:159) ~[na:1.8.0_74] at com.aol.cyclops.types.futurestream.BlockingStreamHelper.capture(BlockingStreamHelper.java:50) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2] at com.aol.cyclops.types.futurestream.BlockingStreamHelper.getSafe(BlockingStreamHelper.java:74) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2] at com.aol.cyclops.types.futurestream.BlockingStreamHelper.lambda$block$0(BlockingStreamHelper.java:25) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2] at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_74] at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) ~[na:1.8.0_74] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_74] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_74] at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_74] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_74] at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_74] at com.aol.cyclops.types.futurestream.BlockingStreamHelper.block(BlockingStreamHelper.java:26) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2] at com.aol.cyclops.types.futurestream.BlockingStream.block(BlockingStream.java:45) ~[cyclops-react-1.0.0-RC2.2.jar!/:1.0.0-RC2.2]

schoberwirt avatar Mar 23 '16 13:03 schoberwirt

@schoberwirt Excellent work, this is very detailed & useful - thanks!
This is definitely a bug - I'll take more detailed look this afternoon.

johnmcclean avatar Mar 23 '16 13:03 johnmcclean

I have a fix for this issue that will be released in 1.0.0-RC2.3 this weekend.

johnmcclean avatar Mar 25 '16 22:03 johnmcclean

Released in 1.0.0-RC2.3

@schoberwirt Thanks for reporting this issue, do let me know if you still see it (i.e. it's caused by something other than the two issues logged).

johnmcclean avatar Mar 27 '16 21:03 johnmcclean