GlobalBundleCache: Fix ClassNewInstance warning from Error Prone
Error Prone reports: [ClassNewInstance] Class.newInstance() bypasses exception checking; prefer getDeclaredConstructor().newInstance() See https://errorprone.info/bugpattern/ClassNewInstance This was the only occurrence of the warning in the code base; now it's fixed, increase the severity to ERROR to prevent future occurrences. Change-Id: Ic04d1c5d2bd458bbb4bb399d6ce9d147bd48d0b1 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
99a5fa2283
commit
dad9e1ff95
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.nls;
|
package org.eclipse.jgit.nls;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -92,12 +93,13 @@ static synchronized <T extends TranslationBundle> T lookupBundle(Locale locale,
|
||||||
}
|
}
|
||||||
TranslationBundle bundle = bundles.get(type);
|
TranslationBundle bundle = bundles.get(type);
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
bundle = type.newInstance();
|
bundle = type.getDeclaredConstructor().newInstance();
|
||||||
bundle.load(locale);
|
bundle.load(locale);
|
||||||
bundles.put(type, bundle);
|
bundles.put(type, bundle);
|
||||||
}
|
}
|
||||||
return (T) bundle;
|
return (T) bundle;
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (InstantiationException | IllegalAccessException
|
||||||
|
| InvocationTargetException | NoSuchMethodException e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ java_package_configuration(
|
||||||
"-Xep:BoxedPrimitiveConstructor:ERROR",
|
"-Xep:BoxedPrimitiveConstructor:ERROR",
|
||||||
"-Xep:CannotMockFinalClass:ERROR",
|
"-Xep:CannotMockFinalClass:ERROR",
|
||||||
"-Xep:ClassCanBeStatic:ERROR",
|
"-Xep:ClassCanBeStatic:ERROR",
|
||||||
"-Xep:ClassNewInstance:WARN",
|
"-Xep:ClassNewInstance:ERROR",
|
||||||
"-Xep:DefaultCharset:ERROR",
|
"-Xep:DefaultCharset:ERROR",
|
||||||
"-Xep:DoubleCheckedLocking:ERROR",
|
"-Xep:DoubleCheckedLocking:ERROR",
|
||||||
"-Xep:ElementsCountedInLoop:ERROR",
|
"-Xep:ElementsCountedInLoop:ERROR",
|
||||||
|
|
Loading…
Reference in New Issue