typetools / typetools/checker-framework
Inferring array element type for nested arrays
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
When the component type of an array creation expression is itself an array creation expression, the element type of the outermost array is not correctly inferred, resulting in type-checking errors.
See file checker-framework/checker/tests/nullness/ArrayCreationSubArray.java, where several array creation expressions do not typecheck: those on the right-hand side of the assignments to o3a, o3b, and o3d. Here is the source code for reference:
public class ArrayCreationSubArray {
void m() {
Object o1a = new Integer[] {1, 2, null, 3, 4};
@Nullable Integer[] o1b = new Integer[] {1, 2, null, 3, 4};
Object o2a = new Object[] {null};
Object o2b = new @Nullable Object[] {null};
Object o3a = new Object[][] {new Object[] {null}};
Object o3b = new Object[][] {new @Nullable Object[] {null}};
Object o3c = new @Nullable Object[][] {new @Nullable Object[] {null}};
Object o3d = new Object[][] {{null}};
}
}
The type-checker output is:
$ch/bin/javac -processor nullness ArrayCreationSubArray.java
ArrayCreationSubArray.java:18: error: [array.initializer.type.incompatible] incompatible types in array initializer.
Object o3a = new Object[][] {new Object[] {null}};
^
found : @FBCBottom @Nullable Object @Initialized @NonNull []
required: @Initialized @NonNull Object @Initialized @NonNull []
ArrayCreationSubArray.java:19: error: [array.initializer.type.incompatible] incompatible types in array initializer.
Object o3b = new Object[][] {new @Nullable Object[] {null}};
^
found : @FBCBottom @Nullable Object @Initialized @NonNull []
required: @Initialized @NonNull Object @Initialized @NonNull []
ArrayCreationSubArray.java:21: error: [array.initializer.type.incompatible] incompatible types in array initializer.
Object o3d = new Object[][] {{null}};
^
found : @FBCBottom @Nullable Object @Initialized @NonNull []
required: @Initialized @NonNull Object @Initialized @NonNull []
ArrayCreationSubArray.java:21: error: [array.initializer.type.incompatible] incompatible types in array initializer.
Object o3d = new Object[][] {{null}};
^
found : null
required: @Initialized @NonNull Object
4 errors
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with checker-framework/checker/tests/nullness/ArrayCreationSubArray.java and run the nullness checker on its nested array creation expressions. Trace how component types are inferred for the outer array, then confirm that the assignments to o3a, o3b, and o3d type-check without the reported errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100