@@ -2168,4 +2168,173 @@ public void errorSerializationTestArrayComponentNull() {
21682168 .setOutputFileNameAndHeader (ERROR_FILE_NAME , ERROR_FILE_HEADER )
21692169 .doTest ();
21702170 }
2171+
2172+ @ Test
2173+ public void errorSerializationTestArrayComponentNullLocalVariable () {
2174+ SerializationTestHelper <ErrorDisplay > tester = new SerializationTestHelper <>(root );
2175+ tester
2176+ .setArgs (
2177+ Arrays .asList (
2178+ "-d" ,
2179+ temporaryFolder .getRoot ().getAbsolutePath (),
2180+ "-XepOpt:NullAway:AnnotatedPackages=com.uber" ,
2181+ "-XepOpt:NullAway:SerializeFixMetadata=true" ,
2182+ "-XepOpt:NullAway:JSpecifyMode=true" ,
2183+ "-XepOpt:NullAway:FixSerializationConfigPath=" + configPath ))
2184+ .addSourceLines (
2185+ "com/uber/A.java" ,
2186+ "package com.uber;" ,
2187+ "import org.jspecify.annotations.Nullable;" ,
2188+ "public class A {" ,
2189+ " void spin() {" ,
2190+ " String [] foo = {\" SomeRandomWords\" };" ,
2191+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2192+ " foo[1] = null;" ,
2193+ " }" ,
2194+ "}" )
2195+ .setExpectedOutputs (
2196+ new ErrorDisplay (
2197+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2198+ "Writing @Nullable expression into array with @NonNull contents." ,
2199+ "com.uber.A" ,
2200+ "spin()" ,
2201+ 235 ,
2202+ "com/uber/A.java" ,
2203+ "LOCAL_VARIABLE" ,
2204+ "com.uber.A" ,
2205+ "spin()" ,
2206+ "foo" ,
2207+ "null" ,
2208+ "com/uber/A.java" ))
2209+ .setFactory (errorDisplayFactory )
2210+ .setOutputFileNameAndHeader (ERROR_FILE_NAME , ERROR_FILE_HEADER )
2211+ .doTest ();
2212+ }
2213+
2214+ @ Test
2215+ public void errorSerializationTestArrayComponentNullLocalVariableLambda () {
2216+ SerializationTestHelper <ErrorDisplay > tester = new SerializationTestHelper <>(root );
2217+ tester
2218+ .setArgs (
2219+ Arrays .asList (
2220+ "-d" ,
2221+ temporaryFolder .getRoot ().getAbsolutePath (),
2222+ "-XepOpt:NullAway:AnnotatedPackages=com.uber" ,
2223+ "-XepOpt:NullAway:SerializeFixMetadata=true" ,
2224+ "-XepOpt:NullAway:JSpecifyMode=true" ,
2225+ "-XepOpt:NullAway:FixSerializationConfigPath=" + configPath ))
2226+ .addSourceLines (
2227+ "com/uber/A.java" ,
2228+ "package com.uber;" ,
2229+ "import org.jspecify.annotations.Nullable;" ,
2230+ "public class A {" ,
2231+ " A a = new A();" ,
2232+ " public void f() {" ,
2233+ " final Object[] l = new Object[10];" ,
2234+ " class B {" ,
2235+ " void b() {" ,
2236+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2237+ " l[0] = null;" ,
2238+ " }" ,
2239+ " void shadowInLambda() {" ,
2240+ " a.exec(" ,
2241+ " () -> {" ,
2242+ " Object[] l = new Object[10];" ,
2243+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2244+ " l[0] = null;" ,
2245+ " });" ,
2246+ " }" ,
2247+ " void useFieldInLambda(A a) {" ,
2248+ " Object[] l = new Object[10];" ,
2249+ " a.exec(" ,
2250+ " () -> {" ,
2251+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2252+ " l[0] = null;" ,
2253+ " });" ,
2254+ " }" ,
2255+ " }" ,
2256+ " a.exec(new Runnable() {" ,
2257+ " @Override" ,
2258+ " public void run() {" ,
2259+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2260+ " l[0] = null;" ,
2261+ " }" ,
2262+ " });" ,
2263+ " // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents." ,
2264+ " l[0] = null;" ,
2265+ " }" ,
2266+ " void exec(Runnable runnable) {" ,
2267+ " runnable.run();" ,
2268+ " }" ,
2269+ "}" )
2270+ .setExpectedOutputs (
2271+ new ErrorDisplay (
2272+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2273+ "Writing @Nullable expression into array with @NonNull contents." ,
2274+ "com.uber.A$1B" ,
2275+ "b()" ,
2276+ 293 ,
2277+ "com/uber/A.java" ,
2278+ "LOCAL_VARIABLE" ,
2279+ "com.uber.A" ,
2280+ "f()" ,
2281+ "l" ,
2282+ "null" ,
2283+ "com/uber/A.java" ),
2284+ new ErrorDisplay (
2285+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2286+ "Writing @Nullable expression into array with @NonNull contents." ,
2287+ "com.uber.A$1B" ,
2288+ "shadowInLambda()" ,
2289+ 560 ,
2290+ "com/uber/A.java" ,
2291+ "LOCAL_VARIABLE" ,
2292+ "com.uber.A$1B" ,
2293+ "shadowInLambda()" ,
2294+ "l" ,
2295+ "null" ,
2296+ "com/uber/A.java" ),
2297+ new ErrorDisplay (
2298+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2299+ "Writing @Nullable expression into array with @NonNull contents." ,
2300+ "com.uber.A$1B" ,
2301+ "useFieldInLambda(com.uber.A)" ,
2302+ 842 ,
2303+ "com/uber/A.java" ,
2304+ "LOCAL_VARIABLE" ,
2305+ "com.uber.A$1B" ,
2306+ "useFieldInLambda(com.uber.A)" ,
2307+ "l" ,
2308+ "null" ,
2309+ "com/uber/A.java" ),
2310+ new ErrorDisplay (
2311+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2312+ "Writing @Nullable expression into array with @NonNull contents." ,
2313+ "com.uber.A$1" ,
2314+ "run()" ,
2315+ 1068 ,
2316+ "com/uber/A.java" ,
2317+ "LOCAL_VARIABLE" ,
2318+ "com.uber.A" ,
2319+ "f()" ,
2320+ "l" ,
2321+ "null" ,
2322+ "com/uber/A.java" ),
2323+ new ErrorDisplay (
2324+ "ASSIGN_NULLABLE_TO_NONNULL_ARRAY" ,
2325+ "Writing @Nullable expression into array with @NonNull contents." ,
2326+ "com.uber.A" ,
2327+ "f()" ,
2328+ 1198 ,
2329+ "com/uber/A.java" ,
2330+ "LOCAL_VARIABLE" ,
2331+ "com.uber.A" ,
2332+ "f()" ,
2333+ "l" ,
2334+ "null" ,
2335+ "com/uber/A.java" ))
2336+ .setFactory (errorDisplayFactory )
2337+ .setOutputFileNameAndHeader (ERROR_FILE_NAME , ERROR_FILE_HEADER )
2338+ .doTest ();
2339+ }
21712340}
0 commit comments