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 ignoreannotations; 17 18 import org.jspecify.annotations.NullMarked; 19 import org.jspecify.annotations.Nullable; 20 import org.jspecify.annotations.NullnessUnspecified; 21 22 @NullMarked 23 public class IgnoreAnnotations { 24 public @Nullable Derived field = null; 25 foo(Derived x, @NullnessUnspecified Base y)26 public @Nullable Derived foo(Derived x, @NullnessUnspecified Base y) { 27 return null; 28 } 29 everythingNotNullable(Derived x)30 public Derived everythingNotNullable(Derived x) { 31 // jspecify_nullness_mismatch 32 return null; 33 } 34 everythingNullable(@ullable Derived x)35 public @Nullable Derived everythingNullable(@Nullable Derived x) { 36 return null; 37 } 38 everythingUnknown(@ullnessUnspecified Derived x)39 public @NullnessUnspecified Derived everythingUnknown(@NullnessUnspecified Derived x) { 40 // jspecify_nullness_not_enough_information 41 return null; 42 } 43 } 44 45 class Base { foo()46 void foo() {} 47 } 48 49 class Derived extends Base {} 50 51 @NullMarked 52 class Instances { 53 static final IgnoreAnnotations IGNORE_ANNOTATIONS = new IgnoreAnnotations(); 54 static final Derived DERIVED = new Derived(); 55 } 56 57 class Use { main()58 static void main() { 59 IgnoreAnnotations a = Instances.IGNORE_ANNOTATIONS; 60 Derived x = Instances.DERIVED; 61 62 // jspecify_nullness_mismatch 63 a.foo(x, null).foo(); 64 // jspecify_nullness_mismatch 65 a.foo(null, x).foo(); 66 67 // jspecify_nullness_mismatch 68 a.field.foo(); 69 70 // jspecify_nullness_mismatch 71 a.everythingNotNullable(null).foo(); 72 a.everythingNotNullable(x).foo(); 73 74 // jspecify_nullness_mismatch 75 a.everythingNullable(null).foo(); 76 77 // jspecify_nullness_not_enough_information 78 a.everythingUnknown(null).foo(); 79 } 80 } 81