@@ -130,11 +130,7 @@ public String getStringBody() {
130
130
}
131
131
132
132
public String getStringBody (String def ) {
133
- if (body == null ) {
134
- return def ;
135
- } else {
136
- return body ;
137
- }
133
+ return body == null ? def : body ;
138
134
}
139
135
140
136
public Boolean getBooleanBody () {
@@ -219,6 +215,8 @@ public Boolean getBooleanAttribute(String name) {
219
215
220
216
public Boolean getBooleanAttribute (String name , Boolean def ) {
221
217
String value = attributes .getProperty (name );
218
+ // Note that ternary operator will throw NPE in some scenarios, just be careful.
219
+ // see this explanation[https://stackoverflow.com/questions/5246776/java-weird-nullpointerexception-in-ternary-operator/5246820#5246820]
222
220
return value == null ? def : Boolean .valueOf (value );
223
221
}
224
222
@@ -228,7 +226,7 @@ public Integer getIntAttribute(String name) {
228
226
229
227
public Integer getIntAttribute (String name , Integer def ) {
230
228
String value = attributes .getProperty (name );
231
- return value == null ? def : Integer .parseInt (value );
229
+ return value == null ? def : Integer .valueOf (value );
232
230
}
233
231
234
232
public Long getLongAttribute (String name ) {
@@ -237,7 +235,7 @@ public Long getLongAttribute(String name) {
237
235
238
236
public Long getLongAttribute (String name , Long def ) {
239
237
String value = attributes .getProperty (name );
240
- return value == null ? def : Long .parseLong (value );
238
+ return value == null ? def : Long .valueOf (value );
241
239
}
242
240
243
241
public Double getDoubleAttribute (String name ) {
@@ -246,7 +244,7 @@ public Double getDoubleAttribute(String name) {
246
244
247
245
public Double getDoubleAttribute (String name , Double def ) {
248
246
String value = attributes .getProperty (name );
249
- return value == null ? def : Double .parseDouble (value );
247
+ return value == null ? def : Double .valueOf (value );
250
248
}
251
249
252
250
public Float getFloatAttribute (String name ) {
@@ -255,7 +253,7 @@ public Float getFloatAttribute(String name) {
255
253
256
254
public Float getFloatAttribute (String name , Float def ) {
257
255
String value = attributes .getProperty (name );
258
- return value == null ? def : Float .parseFloat (value );
256
+ return value == null ? def : Float .valueOf (value );
259
257
}
260
258
261
259
public List <XNode > getChildren () {
0 commit comments