Commit dd0da6d
issue 1275 - report unboxing warning for for-each loop (#1281)
The core of the solution is a new check that activates when the loop
variable is a primitive type
For arrays (e.g., @nullable Integer[]), the existing
NullabilityUtil.isArrayElementNullable utility is used to determine if
the elements can be null.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* New Features
* Adds a JSpecify-only check that flags unsafe auto-unboxing in enhanced
for-each loops over arrays when elements may be nullable and the loop
variable is primitive. Clear diagnostic provided. No impact outside
JSpecify mode.
* Tests
* Added tests covering nullable and non-null array elements in for-each
unboxing scenarios.
* Introduced a test-only Nullable annotation and additional cases
validating array element nullability behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Manu Sridharan <msridhar@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>1 parent 533986c commit dd0da6d
File tree
2 files changed
+55
-0
lines changed- nullaway/src
- main/java/com/uber/nullaway
- test/java/com/uber/nullaway/jspecify
2 files changed
+55
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1852 | 1852 | | |
1853 | 1853 | | |
1854 | 1854 | | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
1855 | 1879 | | |
1856 | 1880 | | |
1857 | 1881 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
675 | 706 | | |
676 | 707 | | |
677 | 708 | | |
| |||
0 commit comments