Skip to content

Commit 89f5425

Browse files
ifradeogerritforge-ltd
authored andcommitted
Merge "DefaultTypedConfigGetter: Box values to avoid infinite recursion"
2 parents 072e93f + 097b158 commit 89f5425

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
*/
3333
public class DefaultTypedConfigGetter implements TypedConfigGetter {
3434

35+
@SuppressWarnings("boxed")
3536
@Override
3637
public boolean getBoolean(Config config, String section, String subsection,
3738
String name, boolean defaultValue) {
38-
return getBoolean(config, section, subsection, name, defaultValue);
39+
return neverNull(getBoolean(config, section, subsection, name,
40+
Boolean.valueOf(defaultValue)));
3941
}
4042

4143
@Nullable
@@ -116,7 +118,8 @@ public <T extends Enum<?>> T getEnum(Config config, T[] all, String section,
116118
@Override
117119
public int getInt(Config config, String section, String subsection,
118120
String name, int defaultValue) {
119-
return getInt(config, section, subsection, name, defaultValue);
121+
return neverNull(getInt(config, section, subsection, name,
122+
Integer.valueOf(defaultValue)));
120123
}
121124

122125
@Nullable
@@ -144,8 +147,8 @@ public Integer getInt(Config config, String section, String subsection,
144147
@Override
145148
public int getIntInRange(Config config, String section, String subsection,
146149
String name, int minValue, int maxValue, int defaultValue) {
147-
return getIntInRange(config, section, subsection, name, minValue,
148-
maxValue, defaultValue);
150+
return neverNull(getIntInRange(config, section, subsection, name,
151+
minValue, maxValue, Integer.valueOf(defaultValue)));
149152
}
150153

151154
@Override
@@ -161,9 +164,9 @@ public Integer getIntInRange(Config config, String section,
161164
return val;
162165
}
163166
if (subsection == null) {
164-
throw new IllegalArgumentException(MessageFormat.format(
165-
JGitText.get().integerValueNotInRange, section, name,
166-
val, minValue, maxValue));
167+
throw new IllegalArgumentException(
168+
MessageFormat.format(JGitText.get().integerValueNotInRange,
169+
section, name, val, minValue, maxValue));
167170
}
168171
throw new IllegalArgumentException(MessageFormat.format(
169172
JGitText.get().integerValueNotInRangeSubSection, section,
@@ -173,7 +176,8 @@ public Integer getIntInRange(Config config, String section,
173176
@Override
174177
public long getLong(Config config, String section, String subsection,
175178
String name, long defaultValue) {
176-
return getLong(config, section, subsection, name, defaultValue);
179+
return neverNull(getLong(config, section, subsection, name,
180+
Long.valueOf(defaultValue)));
177181
}
178182

179183
@Nullable
@@ -190,18 +194,18 @@ public Long getLong(Config config, String section, String subsection,
190194
// Empty
191195
return defaultValue;
192196
} catch (NumberFormatException nfe) {
193-
throw new IllegalArgumentException(MessageFormat.format(
194-
JGitText.get().invalidIntegerValue, section, name, str),
197+
throw new IllegalArgumentException(
198+
MessageFormat.format(JGitText.get().invalidIntegerValue,
199+
section, name, str),
195200
nfe);
196201
}
197202
}
198203

199204
@Override
200205
public long getTimeUnit(Config config, String section, String subsection,
201206
String name, long defaultValue, TimeUnit wantUnit) {
202-
Long v = getTimeUnit(config, section, subsection, name,
203-
Long.valueOf(defaultValue), wantUnit);
204-
return v == null ? defaultValue : v.longValue();
207+
return neverNull(getTimeUnit(config, section, subsection, name,
208+
Long.valueOf(defaultValue), wantUnit));
205209
}
206210

207211
@Override
@@ -325,4 +329,14 @@ public List<RefSpec> getRefSpecs(Config config, String section,
325329
}
326330
return result;
327331
}
332+
333+
// Trick for the checkers. When we use this, one is never null, but
334+
// they don't know.
335+
@NonNull
336+
private static <T> T neverNull(T one) {
337+
if (one == null) {
338+
throw new IllegalArgumentException();
339+
}
340+
return one;
341+
}
328342
}

0 commit comments

Comments
 (0)