32
32
*/
33
33
public class DefaultTypedConfigGetter implements TypedConfigGetter {
34
34
35
+ @ SuppressWarnings ("boxed" )
35
36
@ Override
36
37
public boolean getBoolean (Config config , String section , String subsection ,
37
38
String name , boolean defaultValue ) {
38
- return getBoolean (config , section , subsection , name , defaultValue );
39
+ return neverNull (getBoolean (config , section , subsection , name ,
40
+ Boolean .valueOf (defaultValue )));
39
41
}
40
42
41
43
@ Nullable
@@ -116,7 +118,8 @@ public <T extends Enum<?>> T getEnum(Config config, T[] all, String section,
116
118
@ Override
117
119
public int getInt (Config config , String section , String subsection ,
118
120
String name , int defaultValue ) {
119
- return getInt (config , section , subsection , name , defaultValue );
121
+ return neverNull (getInt (config , section , subsection , name ,
122
+ Integer .valueOf (defaultValue )));
120
123
}
121
124
122
125
@ Nullable
@@ -144,8 +147,8 @@ public Integer getInt(Config config, String section, String subsection,
144
147
@ Override
145
148
public int getIntInRange (Config config , String section , String subsection ,
146
149
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 )) );
149
152
}
150
153
151
154
@ Override
@@ -161,9 +164,9 @@ public Integer getIntInRange(Config config, String section,
161
164
return val ;
162
165
}
163
166
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 ));
167
170
}
168
171
throw new IllegalArgumentException (MessageFormat .format (
169
172
JGitText .get ().integerValueNotInRangeSubSection , section ,
@@ -173,7 +176,8 @@ public Integer getIntInRange(Config config, String section,
173
176
@ Override
174
177
public long getLong (Config config , String section , String subsection ,
175
178
String name , long defaultValue ) {
176
- return getLong (config , section , subsection , name , defaultValue );
179
+ return neverNull (getLong (config , section , subsection , name ,
180
+ Long .valueOf (defaultValue )));
177
181
}
178
182
179
183
@ Nullable
@@ -190,18 +194,18 @@ public Long getLong(Config config, String section, String subsection,
190
194
// Empty
191
195
return defaultValue ;
192
196
} 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 ),
195
200
nfe );
196
201
}
197
202
}
198
203
199
204
@ Override
200
205
public long getTimeUnit (Config config , String section , String subsection ,
201
206
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 ));
205
209
}
206
210
207
211
@ Override
@@ -325,4 +329,14 @@ public List<RefSpec> getRefSpecs(Config config, String section,
325
329
}
326
330
return result ;
327
331
}
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
+ }
328
342
}
0 commit comments