biddyweb / checker-framework

Automatically exported from code.google.com/p/checker-framework
Other
0 stars 1 forks source link

Bogus Warning for OptionalInt.orElseThrow, OptionalDouble.orElseThrow, and OptionalLong.orElseThrow (but not for Optional<T>.orElseThrow) #363

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Run the NullnessChecker for

package test;

class Test {
    static void foo(java.util.OptionalInt value) {
        value.orElseThrow(() -> new Error());
    }

    static void bar(java.util.OptionalInt value) {
        java.util.function.Supplier<Error> s = () -> new Error();
        value.orElseThrow(s);
    }
}

What is the expected output? What do you see instead?
Expected: no error
Actual: 
Test.java:5: error: [return.type.incompatible] incompatible types in return.
        value.orElseThrow(() -> new Error());
                                ^
  found   : @Initialized @NonNull Error
  required: X extends @Initialized @NonNull Throwable
1 error

What version of the product are you using? On what operating system?
1.8.6 on Windows 8.1, Java 8

Please provide any additional information below.
The bug can be reproduced also with OptionalLong and OptionalDouble, but not 
with Optional<T>

Note that the signature of Optional<T>.orElseThrow contains extends twice (I 
don't know what this is good for):
<X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) 
throws X;

while the signature for OptionalInt.orElseThrow, OptionalDouble.orElseThrow, 
and OptionalLong.orElseThrow is:
<X extends Throwable> int/double/long orElseThrow(Supplier<X> 
exceptionSupplier) throws X {

Original issue reported on code.google.com by ClovisSe...@gmail.com on 27 Sep 2014 at 11:41

GoogleCodeExporter commented 9 years ago
Hi Clovis,

Thanks for the report! This issue is fixed in our private 
typevariable-improvements repository which we are planning to merge into 
mainline within the next couple of releases.

Original comment by mcart...@cs.washington.edu on 26 Jan 2015 at 6:58