xref: /aosp_15_r20/external/jspecify/samples/ExtendsVsExtendsNullable.java (revision 2167191df2fa07300797f1ac5b707370b5f38c48)
1 /*
2  * Copyright 2022 The JSpecify Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 import org.jspecify.annotations.NullMarked;
17 import org.jspecify.annotations.Nullable;
18 import org.jspecify.annotations.NullnessUnspecified;
19 
20 @NullMarked
21 interface ExtendsVsExtendsNullable {
22   interface Supplier<T extends @Nullable Object> {}
23 
24   interface Other<T> {}
25 
x(Supplier<? extends T> s, Other<T> o)26   default <T> void x(Supplier<? extends T> s, Other<T> o) {
27     useNonNullBounded(s, o);
28     useUnspecBounded(s, o);
29     useUnionNullBounded(s, o);
30   }
31 
x1(Supplier<? extends @NullnessUnspecified T> s, Other<T> o)32   default <T> void x1(Supplier<? extends @NullnessUnspecified T> s, Other<T> o) {
33     // jspecify_nullness_not_enough_information
34     useNonNullBounded(s, o);
35     // jspecify_nullness_not_enough_information
36     useUnspecBounded(s, o);
37     useUnionNullBounded(s, o);
38   }
39 
x2(Supplier<? extends @Nullable T> s, Other<T> o)40   default <T> void x2(Supplier<? extends @Nullable T> s, Other<T> o) {
41     // jspecify_nullness_mismatch
42     useNonNullBounded(s, o);
43     // jspecify_nullness_not_enough_information
44     useUnspecBounded(s, o);
45     useUnionNullBounded(s, o);
46   }
47 
useNonNullBounded(Supplier<? extends T> s, Other<T> o)48   <T> void useNonNullBounded(Supplier<? extends T> s, Other<T> o);
49 
useUnspecBounded(Supplier<? extends @NullnessUnspecified T> s, Other<T> o)50   <T> void useUnspecBounded(Supplier<? extends @NullnessUnspecified T> s, Other<T> o);
51 
useUnionNullBounded(Supplier<? extends @Nullable T> s, Other<T> o)52   <T> void useUnionNullBounded(Supplier<? extends @Nullable T> s, Other<T> o);
53 }
54