ErrorProne: Enable and fix UnusedException check
Enable UnusedException at ERROR level which causes the build to fail in many places with: [UnusedException] This catch block catches an symbol and re-throws another, but swallows the caught symbol rather than setting it as a cause. This can make debugging harder. Fix it by setting the caught exception as cause on the subsequently thrown exception, or logging it. Note: The grammatically incorrect error message is copy-pasted as-is from the version of ErrorProne currently used in Bazel; it has been fixed by [1] in the latest version. [1] https://github.com/google/error-prone/commit/d57a39c Change-Id: Ia7a7658e01740e844459a90226efdcf8592561e0
This commit is contained in:
@@ -30,7 +30,6 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class ConfigUtil {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T[] allValuesOf(T defaultValue) {
|
||||
try {
|
||||
@@ -182,7 +181,7 @@ public class ConfigUtil {
|
||||
try {
|
||||
return getTimeUnit(s, defaultValue, wantUnit);
|
||||
} catch (IllegalArgumentException notTime) {
|
||||
throw notTimeUnit(section, subsection, setting, valueString);
|
||||
throw notTimeUnit(section, subsection, setting, valueString, notTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +249,7 @@ public class ConfigUtil {
|
||||
try {
|
||||
return wantUnit.convert(Long.parseLong(digits) * inputMul, inputUnit);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw notTimeUnit(valueString);
|
||||
throw notTimeUnit(valueString, nfe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,13 +420,21 @@ public class ConfigUtil {
|
||||
}
|
||||
|
||||
private static IllegalArgumentException notTimeUnit(
|
||||
final String section,
|
||||
final String subsection,
|
||||
final String setting,
|
||||
final String valueString) {
|
||||
return new IllegalArgumentException(
|
||||
"Invalid time unit value: "
|
||||
+ section
|
||||
String section, String subsection, String setting, String valueString, Throwable why) {
|
||||
return notTimeUnit(
|
||||
section
|
||||
+ (subsection != null ? "." + subsection : "")
|
||||
+ "."
|
||||
+ setting
|
||||
+ " = "
|
||||
+ valueString,
|
||||
why);
|
||||
}
|
||||
|
||||
private static IllegalArgumentException notTimeUnit(
|
||||
String section, String subsection, String setting, String valueString) {
|
||||
return notTimeUnit(
|
||||
section
|
||||
+ (subsection != null ? "." + subsection : "")
|
||||
+ "."
|
||||
+ setting
|
||||
@@ -439,5 +446,9 @@ public class ConfigUtil {
|
||||
return new IllegalArgumentException("Invalid time unit value: " + val);
|
||||
}
|
||||
|
||||
private static IllegalArgumentException notTimeUnit(String val, Throwable why) {
|
||||
return new IllegalArgumentException("Invalid time unit value: " + val, why);
|
||||
}
|
||||
|
||||
private ConfigUtil() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user