Closed nimakarimipour closed 1 year ago
Tested on Checker Framework version 3.37.0-SNAPSHOT (master branch)
3.37.0-SNAPSHOT
I was working with TaintingChecker and saw the reported errors from the CF on the code snippet below ([demo](http://eisop.uwaterloo.ca/live/#mode=display&code=import+org.checkerframework.checker.tainting.qual.Untainted%3B%0Aimport+java.util.Collections%3B%0Aimport+java.util.Collection%3B%0Aimport+java.util.List%3B%0Aimport+java.util.ArrayList%3B%0A%0Aclass+Foo%3CE%3E+%7B%0A++public+void+bar(List%3CE%3E+list)+%7B%0A++++++Collection%3C%3F+extends+E%3E+c+%3D+list+!%3D+null+%3F+list+%3A+Collections.emptyList()%3B%0A++%7D%0A%7D&typeSystem=nullness)):
TaintingChecker
import org.checkerframework.checker.tainting.qual.Untainted; import java.util.Collections; import java.util.Collection; import java.util.List; import java.util.ArrayList; class Foo<E> { public void bar(List<E> list) { Collection<? extends E> c = list != null ? list : Collections.emptyList(); // reported error here } }
The Checker Framework reports three errors on the designated line, please find them below:
error: [assignment] incompatible types in assignment. Collection<? extends E> c = list != null ? list : Collections.emptyList(); ^ found : @Tainted Collection<?[ extends E[ extends @Tainted Object super @Tainted Void] super @Untainted Void]> required: @Tainted Collection<?[ extends E[ extends @Tainted Object super @Untainted Void] super @Untainted Void]> error: [conditional] incompatible types in conditional expression. Collection<? extends E> c = list != null ? list : Collections.emptyList(); ^ found : @Tainted List<E[ extends @Tainted Object super @Untainted Void]> required: @Tainted Collection<?[ extends E[ extends @Tainted Object super @Tainted Void] super @Untainted Void]> error: [conditional] incompatible types in conditional expression. Collection<? extends E> c = list != null ? list : Collections.emptyList(); ^ found : @Tainted List<E[ extends @Tainted Object super @Untainted Void]> required: @Tainted Collection<?[ extends E[ extends @Tainted Object super @Tainted Void] super @Untainted Void]>
Please note that if the line is written in any of the cases below, we won't see any errors:
Collection<? extends E> c = list;
Collection<? extends E> c = Collections.emptyList();
Collection<E> c = list != null ? list : Collections.emptyList();
Collection<?> c = list != null ? list : Collections.emptyList();
Would you please let me know if this behavior is expected, or if there is way to resolve the errors. Thank you very much.
Thanks for reporting! This is a bug, which I've fixed in #6114.
@smillst Thank you for the quick reply and the fix, will try the fix.
Tested on Checker Framework version
3.37.0-SNAPSHOT
(master branch)I was working with
TaintingChecker
and saw the reported errors from the CF on the code snippet below ([demo](http://eisop.uwaterloo.ca/live/#mode=display&code=import+org.checkerframework.checker.tainting.qual.Untainted%3B%0Aimport+java.util.Collections%3B%0Aimport+java.util.Collection%3B%0Aimport+java.util.List%3B%0Aimport+java.util.ArrayList%3B%0A%0Aclass+Foo%3CE%3E+%7B%0A++public+void+bar(List%3CE%3E+list)+%7B%0A++++++Collection%3C%3F+extends+E%3E+c+%3D+list+!%3D+null+%3F+list+%3A+Collections.emptyList()%3B%0A++%7D%0A%7D&typeSystem=nullness)):The Checker Framework reports three errors on the designated line, please find them below:
Please note that if the line is written in any of the cases below, we won't see any errors:
Collection<? extends E> c = list;
Collection<? extends E> c = Collections.emptyList();
Collection<E> c = list != null ? list : Collections.emptyList();
Collection<?> c = list != null ? list : Collections.emptyList();
Would you please let me know if this behavior is expected, or if there is way to resolve the errors. Thank you very much.