Debian Codegraph @

samples/nullnessUnspecifiedTypeParameter/nullnessunspecifiedtypeparameter/NullnessUnspecifiedTypeParameter.java

raw
1 /*
2 * Copyright 2020 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 package nullnessunspecifiedtypeparameter;
17
18 import org.jspecify.annotations.NullMarked;
19 import org.jspecify.annotations.Nullable;
20
21 @NullMarked
22 public class NullnessUnspecifiedTypeParameter<T> {
23 public void foo(T t) {}
24
25 public void bar(Test s, T t) {}
26 }
27
28 class Test {}
29
30 @NullMarked
31 class Instances {
32 static final NullnessUnspecifiedTypeParameter<Object> A1 =
33 new NullnessUnspecifiedTypeParameter<>();
34 // jspecify_nullness_mismatch
35 static final NullnessUnspecifiedTypeParameter<@Nullable Object> A2 =
36 new NullnessUnspecifiedTypeParameter<>();
37 static final Test X = new Test();
38 }
39
40 class Use extends Instances {
41 void main() {
42 // jspecify_nullness_mismatch
43 A1.foo(null);
44 A1.foo(1);
45
46 // jspecify_nullness_mismatch
47 A2.foo(null);
48 A2.foo(1);
49
50 // jspecify_nullness_mismatch
51 A1.bar(null, null);
52 // jspecify_nullness_mismatch
53 A1.bar(X, null);
54 A1.bar(X, 1);
55
56 // jspecify_nullness_mismatch
57 A2.bar(null, null);
58 // jspecify_nullness_mismatch
59 A2.bar(X, null);
60 A2.bar(X, 1);
61 }
62 }