Incorrect warning from AlreadyChecked
norrisjeremy opened this issue · comments
Jeremy Norris commented
The following code incorrectly generates a warning with the new introduced AlreadyChecked
:
if (this && that) return "this and that";
else if (this) return "this";
else if (that) return "that";
else return "";
[WARNING] ... [AlreadyChecked] This condition (on this) is already known to be true; it (or its complement) has already been checked.
(see https://errorprone.info/bugpattern/AlreadyChecked)
[WARNING] ... [AlreadyChecked] This condition (on that) is already known to be true; it (or its complement) has already been checked.
(see https://errorprone.info/bugpattern/AlreadyChecked)
Liam Miller-Cushon commented
Thanks, I agree that seems off:
class T {
String f(boolean ths, boolean that) {
if (ths && that) return "this and that";
else if (ths) return "this";
else if (that) return "that";
else return "";
}
}
javac \
-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
-XDcompilePolicy=simple \
-processorpath error_prone_core-2.11.0-with-dependencies.jar:dataflow-errorprone-3.15.0.jar \
'-Xplugin:ErrorProne -XepDisableAllChecks -Xep:AlreadyChecked:ERROR' \
T.java
T.java
T.java:4: error: [AlreadyChecked] This condition (on ths) is already known to be true; it (or its complement) has already been checked.
else if (ths) return "this";
^
(see https://errorprone.info/bugpattern/AlreadyChecked)
T.java:5: error: [AlreadyChecked] This condition (on that) is already known to be true; it (or its complement) has already been checked.
else if (that) return "that";
^
(see https://errorprone.info/bugpattern/AlreadyChecked)
2 errors