@@ -67,6 +67,105 @@ public void lambdas() {
67
67
.doTest ();
68
68
}
69
69
70
+ @ Test
71
+ public void rootedAtParameterOrLocal () {
72
+ defaultCompilationHelper
73
+ .addSourceLines (
74
+ "Test.java" ,
75
+ "package com.uber;" ,
76
+ "import com.uber.nullaway.annotations.MonotonicNonNull;" ,
77
+ "class Test {" ,
78
+ " @MonotonicNonNull Object f1;" ,
79
+ " void testPositiveParam(Test t) {" ,
80
+ " Runnable r = () -> {" ,
81
+ " // BUG: Diagnostic contains: dereferenced expression t.f1" ,
82
+ " t.f1.toString();" ,
83
+ " };" ,
84
+ " }" ,
85
+ " void testNegativeParam(Test t) {" ,
86
+ " t.f1 = new Object();" ,
87
+ " Runnable r = () -> {" ,
88
+ " t.f1.toString();" ,
89
+ " };" ,
90
+ " }" ,
91
+ " void testPositiveLocal() {" ,
92
+ " Test t = new Test();" ,
93
+ " Runnable r = () -> {" ,
94
+ " // BUG: Diagnostic contains: dereferenced expression t.f1" ,
95
+ " t.f1.toString();" ,
96
+ " };" ,
97
+ " }" ,
98
+ " void testNegativeLocal() {" ,
99
+ " Test t = new Test();" ,
100
+ " t.f1 = new Object();" ,
101
+ " Runnable r = () -> {" ,
102
+ " t.f1.toString();" ,
103
+ " };" ,
104
+ " }" ,
105
+ "}" )
106
+ .doTest ();
107
+ }
108
+
109
+ @ Test
110
+ public void rootedAtStaticFinal () {
111
+ defaultCompilationHelper
112
+ .addSourceLines (
113
+ "Test.java" ,
114
+ "package com.uber;" ,
115
+ "import com.uber.nullaway.annotations.MonotonicNonNull;" ,
116
+ "class Test {" ,
117
+ " @MonotonicNonNull Object f1;" ,
118
+ " static final Test t = new Test();" ,
119
+ " void testPositive() {" ,
120
+ " Runnable r = () -> {" ,
121
+ " // BUG: Diagnostic contains: dereferenced expression t.f1" ,
122
+ " t.f1.toString();" ,
123
+ " };" ,
124
+ " }" ,
125
+ " void testNegative() {" ,
126
+ " t.f1 = new Object();" ,
127
+ " Runnable r = () -> {" ,
128
+ " t.f1.toString();" ,
129
+ " };" ,
130
+ " }" ,
131
+ "}" )
132
+ .doTest ();
133
+ }
134
+
135
+ @ Test
136
+ public void monotonicNonNullStatic () {
137
+ defaultCompilationHelper
138
+ .addSourceLines (
139
+ "Test.java" ,
140
+ "package com.uber;" ,
141
+ "import com.uber.nullaway.annotations.MonotonicNonNull;" ,
142
+ "import org.jspecify.annotations.Nullable;" ,
143
+ "class Test {" ,
144
+ " @MonotonicNonNull static Object f1;" ,
145
+ " @Nullable static Object f2;" ,
146
+ " void testPositive() {" ,
147
+ " Runnable r = () -> {" ,
148
+ " // BUG: Diagnostic contains: dereferenced expression f1" ,
149
+ " f1.toString();" ,
150
+ " };" ,
151
+ " }" ,
152
+ " void testNegative() {" ,
153
+ " f1 = new Object();" ,
154
+ " Runnable r = () -> {" ,
155
+ " f1.toString();" ,
156
+ " };" ,
157
+ " }" ,
158
+ " void testPositive2() {" ,
159
+ " f2 = new Object();" ,
160
+ " Runnable r = () -> {" ,
161
+ " // BUG: Diagnostic contains: dereferenced expression f2" ,
162
+ " f2.toString();" ,
163
+ " };" ,
164
+ " }" ,
165
+ "}" )
166
+ .doTest ();
167
+ }
168
+
70
169
@ Test
71
170
public void anonymousClasses () {
72
171
defaultCompilationHelper
0 commit comments