mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 18:55:58 +02:00
Fix two ErrorProne warnings in TypeUtils
1) Prefer .getConstructor().newInstance() over .newInstance() because otherwise checked exceptions can be propagated from the constructor even though they aren't declared. 2) Use the type T in the parameters to instantiate(). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=138874730
This commit is contained in:
parent
f742ac8056
commit
d5104df453
2 changed files with 7 additions and 5 deletions
|
@ -46,13 +46,12 @@ public class TypeUtils {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T instantiate(Class<?> clazz) {
|
||||
public static <T> T instantiate(Class<? extends T> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue