typetools / typetools/checker-framework
False positive when assigning result of function with type parameters to var
Open
@smillst is already working on this.
Since Aug 8, 2024.
False Positive (false warning or imprecision)
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Might be related to issue #6675
public class Test {
public static <T> List<T> getInParameter(T value, Class<T> type) {
return new ArrayList<>(5);
}
List<?> getInParameter() {
var value = 5;
var type = Integer.class;
var result = getInParameter(value, type);
return result;
}
}
results in
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java
java: [type.argument] incompatible type argument for type parameter E of List.
found : @UnknownInitialization @NonNull Integer
required: @Initialized @Nullable Object
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:16:32
java: [assignment] incompatible types in assignment.
found : @Initialized @NonNull List<@Initialized @NonNull Integer>
required: @UnknownInitialization @Nullable List<@UnknownInitialization @NonNull Integer>
It should compile without problem.
It compiled in 3.42.0, fails in 3.46.0
If explicit type is specified for target
List<Integer> result = getInParameter(value, type);
it compiles without problem
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.
Assessment
This issue has not been assessed yet.