a test for IDEA-98211 "Constant conditions & exceptions": warning about possible ClassCastException is shown in one case, but one in another similar one

This commit is contained in:
peter
2012-12-27 16:03:47 +01:00
parent 7004edd5df
commit dc22cda945
2 changed files with 23 additions and 0 deletions
@@ -0,0 +1,22 @@
import java.util.Date;
public class DataFlowBug {
private static boolean isNumberable(Object o) {
return o instanceof Number;
}
public Object add(Object left, Object right) {
if (left != null && right != null && (left instanceof Date || right instanceof Date)) {
if (isNumberable(left)) {
return ((<warning descr="Casting 'right' to 'Date' may produce 'java.lang.ClassCastException'">Date</warning>) right).getTime();
}
if (isNumberable(right)) {
return ((<warning descr="Casting 'left' to 'Date' may produce 'java.lang.ClassCastException'">Date</warning>) left).getTime();
}
}
return new Object();
}
}