Java: Don't show warnings at reflection access to members of the class if a subclass could be passed at that place (IDEA-177983, IDEA-173505)

This commit is contained in:
Pavel Dolgov
2017-08-28 14:43:10 +03:00
parent ecf65d0924
commit 032fd07e23
12 changed files with 208 additions and 130 deletions
@@ -0,0 +1,38 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
class Bugs {
static class EnumMethod {
public static <T extends Enum<T>> boolean isEnum(final Class<T> enumClass, final String candidate) {
try {
final Method method = enumClass.getMethod("valueOf", String.class);
Object o = method.invoke(null, candidate);
System.out.println(o.getClass() + "." + o);
return true;
}
catch (final IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
return false;
}
}
}
static class ConstructorInSubclass {
static abstract class X {
}
public static class Y extends X {
public Y(int i) {
System.out.println("ok");
}
}
static X test(Class<? extends X> clazz) throws Exception {
return clazz.getConstructor(int.class)
.newInstance(1);
}
public static void main(String[] args) throws Exception {
test(Y.class);
}
}
}