@@ -434,4 +434,58 @@ public void testAccessUsingExplicitThis() {
434
434
"}" )
435
435
.doTest ();
436
436
}
437
+
438
+ @ Test
439
+ public void mapKeysFromValueOf () {
440
+ defaultCompilationHelper
441
+ .addSourceLines (
442
+ "Foo.java" ,
443
+ "package com.uber;" ,
444
+ "import java.util.HashMap;" ,
445
+ "import java.util.Map;" ,
446
+ "public class Foo {" ,
447
+ " private final Map<Integer, Object> map = new HashMap<>();" ,
448
+ " private final Map<Long, Object> longMap = new HashMap<>();" ,
449
+ " static Integer valueOf(int i) { return 0; }" ,
450
+ " static Integer valueOf(int i, int j) { return i+j; }" ,
451
+ " public void putThenGetIntegerValueOf() {" ,
452
+ " map.put(Integer.valueOf(10), new Object());" ,
453
+ " map.get(Integer.valueOf(10)).toString();" ,
454
+ " }" ,
455
+ " public void putThenGetLongValueOf() {" ,
456
+ " longMap.put(Long.valueOf(10), new Object());" ,
457
+ " longMap.get(Long.valueOf(10)).toString();" ,
458
+ " }" ,
459
+ " public void putThenGetFooValueOf() {" ,
460
+ " map.put(valueOf(10), new Object());" ,
461
+ " // Unknown valueOf method so we report a warning" ,
462
+ " // BUG: Diagnostic contains: dereferenced expression map.get(valueOf(10)) is @Nullable" ,
463
+ " map.get(valueOf(10)).toString();" ,
464
+ " map.put(valueOf(10,20), new Object());" ,
465
+ " // Unknown valueOf method so we report a warning" ,
466
+ " // BUG: Diagnostic contains: dereferenced expression map.get(valueOf(10,20)) is @Nullable" ,
467
+ " map.get(valueOf(10,20)).toString();" ,
468
+ " }" ,
469
+ "}" )
470
+ .doTest ();
471
+ }
472
+
473
+ @ Test
474
+ public void mapKeyFromIntegerValueOfStaticImport () {
475
+ defaultCompilationHelper
476
+ .addSourceLines (
477
+ "Foo.java" ,
478
+ "package com.uber;" ,
479
+ "import java.util.HashMap;" ,
480
+ "import java.util.Map;" ,
481
+ "import static java.lang.Integer.valueOf;" ,
482
+ "public class Foo {" ,
483
+ " private final Map<Integer, Object> map = new HashMap<>();" ,
484
+ " public void putThenGet() {" ,
485
+ " map.put(valueOf(10), new Object());" ,
486
+ " map.get(valueOf(10)).toString();" ,
487
+ " }" ,
488
+ "}" )
489
+ .doTest ();
490
+ }
437
491
}
0 commit comments