Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/ClassCastExceptionDispatch.java
Tagir Valeev 343a57fe88 DFA: dispatch ClassCastException (IDEA-220077)
GitOrigin-RevId: e8b185f4300b4f319a7e6a06ee3000a56777ee92
2019-08-09 15:03:05 +03:00

43 lines
1.1 KiB
Java

class X {
public static void main(final String[] args) {
final Object obj = getObject();
String str = null;
try {
str = (String) obj;
} catch (final AssertionError ignored) {
if (obj instanceof String) {}
if (str != null) {}
} catch (final ClassCastException ignored) {
if (<warning descr="Condition 'obj instanceof String' is always 'false'">obj instanceof String</warning>) {}
if (<warning descr="Condition 'obj == null' is always 'false'">obj == null</warning>) {}
if (<warning descr="Condition 'str != null' is always 'false'">str != null</warning>) {}
}
if (str != null) {
System.out.println("str = " + str);
}
}
private static native Object getObject();
void testDoubleCatch(Object obj) {
try {
System.out.println(((String)obj).length());
}
catch (Exception ex) {}
try {
System.out.println(((String)obj).trim());
}
catch (Exception ex) {}
}
void testFinally(Object obj) {
try {
System.out.println(((String)obj).length());
}
catch (Exception ex) {}
finally {
System.out.println(((String)obj).trim());
}
}
}