diff --git a/java/google/registry/model/index/ForeignKeyIndex.java b/java/google/registry/model/index/ForeignKeyIndex.java index 49a8f7934..e2fd1675a 100644 --- a/java/google/registry/model/index/ForeignKeyIndex.java +++ b/java/google/registry/model/index/ForeignKeyIndex.java @@ -103,7 +103,10 @@ public abstract class ForeignKeyIndex extends BackupGroup */ public static ForeignKeyIndex create( E resource, DateTime deletionTime) { - ForeignKeyIndex instance = instantiate(RESOURCE_CLASS_TO_FKI_CLASS.get(resource.getClass())); + @SuppressWarnings("unchecked") + Class> fkiClass = + (Class>) RESOURCE_CLASS_TO_FKI_CLASS.get(resource.getClass()); + ForeignKeyIndex instance = instantiate(fkiClass); instance.topReference = Key.create(resource); instance.foreignKey = resource.getForeignKey(); instance.deletionTime = deletionTime; diff --git a/java/google/registry/util/TypeUtils.java b/java/google/registry/util/TypeUtils.java index dc979dc63..86aa0655b 100644 --- a/java/google/registry/util/TypeUtils.java +++ b/java/google/registry/util/TypeUtils.java @@ -46,13 +46,12 @@ public class TypeUtils { } } - @SuppressWarnings("unchecked") - public static T instantiate(Class clazz) { + public static T instantiate(Class clazz) { checkArgument(Modifier.isPublic(clazz.getModifiers()), "AppEngine's custom security manager won't let us reflectively access non-public types"); try { - return (T) clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return clazz.getConstructor().newInstance(); + } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } }