GWT-CompletableFuture icon indicating copy to clipboard operation
GWT-CompletableFuture copied to clipboard

Added Promise.then method for handling cases where the value is Void …

Open kitschen opened this issue 3 years ago • 1 comments

…(notably in allOf), as this was breaking GWT)

kitschen avatar Dec 10 '21 21:12 kitschen

More precisely, the issue appears in this situation: Code in compiling with GWT:


        CompletableFuture<String> ft1 = new CompletableFuture<>();
        CompletableFuture<String> ft2 = new CompletableFuture<>();
        CompletableFuture<Void> all = CompletableFuture.allOf(ft1, ft2);
        all.whenComplete((value,reason) -> {
            logger.log(Level.SEVERE, "Received " + value + " " + reason);
        });
        ft1.complete("Hello");
        ft2.complete("World");
        // expecting the whenComplete to print "Received null null"

Instead of prrint, we get a stacktrace in the Javascript console

Uncaught (in promise) Error: java.lang.ClassCastException
    at ClassCastException_2_g$.createError_0_g$ [as createError_2_g$] (Throwable.java:117)
    at ClassCastException_2_g$.initializeBackingError_0_g$ [as initializeBackingError_1_g$] (Throwable.java:109)
    at ClassCastException_2_g$.Throwable_3_g$ (Throwable.java:69)
    at ClassCastException_2_g$.Exception_3_g$ (Exception.java:29)
    at ClassCastException_2_g$.RuntimeException_3_g$ (RuntimeException.java:29)
    at new ClassCastException_2_g$ (ClassCastException.java:27)
    at checkCriticalType_1_g$ (InternalPreconditions.java:154)
    at checkType_1_g$ (InternalPreconditions.java:138)
    at checkType_0_g$ (InternalPreconditions.java:133)
    at castTo_0_g$ (Cast.java:75)
    at CompletableFuture$lambda$2$Type_1_g$.accept_25_g$ [as accept_120_g$] (CompletableFuture.java:94)
    at lambda$1_3_g$ (NativePromiseImpl.java:57)
    at Function.onSettled_0_g$ (NativePromiseImpl.java:57)
    at lambda_0_g$ (Runtime.java:166)```

kitschen avatar Dec 11 '21 08:12 kitschen