aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2025-02-13 00:24:33 +0000
committerGerrit Code Review <support@gerrithub.io>2025-02-13 00:24:33 +0000
commit89f5425e136c85bc834506bdb83c3cc4fdbebc9b (patch)
tree0264a3836f5458aa4ca9e8504291dd2ad4f69bba /org.eclipse.jgit/src/org
parent072e93fded7229f00002232b33ed91a0ef614ddb (diff)
parent097b158c3b03c275ccef27bdb35c91ccf8372a02 (diff)
downloadjgit-89f5425e136c85bc834506bdb83c3cc4fdbebc9b.tar.gz
jgit-89f5425e136c85bc834506bdb83c3cc4fdbebc9b.zip
Merge "DefaultTypedConfigGetter: Box values to avoid infinite recursion"
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
index 65093987e8..3059f283fe 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
@@ -32,10 +32,12 @@ import org.eclipse.jgit.util.StringUtils;
*/
public class DefaultTypedConfigGetter implements TypedConfigGetter {
+ @SuppressWarnings("boxed")
@Override
public boolean getBoolean(Config config, String section, String subsection,
String name, boolean defaultValue) {
- return getBoolean(config, section, subsection, name, defaultValue);
+ return neverNull(getBoolean(config, section, subsection, name,
+ Boolean.valueOf(defaultValue)));
}
@Nullable
@@ -116,7 +118,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
@Override
public int getInt(Config config, String section, String subsection,
String name, int defaultValue) {
- return getInt(config, section, subsection, name, defaultValue);
+ return neverNull(getInt(config, section, subsection, name,
+ Integer.valueOf(defaultValue)));
}
@Nullable
@@ -144,8 +147,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
@Override
public int getIntInRange(Config config, String section, String subsection,
String name, int minValue, int maxValue, int defaultValue) {
- return getIntInRange(config, section, subsection, name, minValue,
- maxValue, defaultValue);
+ return neverNull(getIntInRange(config, section, subsection, name,
+ minValue, maxValue, Integer.valueOf(defaultValue)));
}
@Override
@@ -161,9 +164,9 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
return val;
}
if (subsection == null) {
- throw new IllegalArgumentException(MessageFormat.format(
- JGitText.get().integerValueNotInRange, section, name,
- val, minValue, maxValue));
+ throw new IllegalArgumentException(
+ MessageFormat.format(JGitText.get().integerValueNotInRange,
+ section, name, val, minValue, maxValue));
}
throw new IllegalArgumentException(MessageFormat.format(
JGitText.get().integerValueNotInRangeSubSection, section,
@@ -173,7 +176,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
@Override
public long getLong(Config config, String section, String subsection,
String name, long defaultValue) {
- return getLong(config, section, subsection, name, defaultValue);
+ return neverNull(getLong(config, section, subsection, name,
+ Long.valueOf(defaultValue)));
}
@Nullable
@@ -190,8 +194,9 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
// Empty
return defaultValue;
} catch (NumberFormatException nfe) {
- throw new IllegalArgumentException(MessageFormat.format(
- JGitText.get().invalidIntegerValue, section, name, str),
+ throw new IllegalArgumentException(
+ MessageFormat.format(JGitText.get().invalidIntegerValue,
+ section, name, str),
nfe);
}
}
@@ -199,9 +204,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
@Override
public long getTimeUnit(Config config, String section, String subsection,
String name, long defaultValue, TimeUnit wantUnit) {
- Long v = getTimeUnit(config, section, subsection, name,
- Long.valueOf(defaultValue), wantUnit);
- return v == null ? defaultValue : v.longValue();
+ return neverNull(getTimeUnit(config, section, subsection, name,
+ Long.valueOf(defaultValue), wantUnit));
}
@Override
@@ -325,4 +329,14 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
}
return result;
}
+
+ // Trick for the checkers. When we use this, one is never null, but
+ // they don't know.
+ @NonNull
+ private static <T> T neverNull(T one) {
+ if (one == null) {
+ throw new IllegalArgumentException();
+ }
+ return one;
+ }
}