<< Back to previous view

[QB-3653] Improve "getBooleanValue" function in 'VariableWrapper.java'
Created: 28/Dec/20  Updated: 02/Feb/21

Status: Resolved
Project: QuickBuild
Component/s: None
Affects Version/s: 10.0.30
Fix Version/s: 10.0.31

Type: Improvement Priority: Minor
Reporter: Jerry Lee Assigned To: Unassigned
Resolution: Fixed Votes: 0
Remaining Estimate: Unknown Time Spent: Unknown
Original Estimate: Unknown
Environment: All platform


 Description   
In case of 'getBooleanValue' function, it may raise Null Pointer Exception because of 'equalsIgnoreCase' withtou null check.
```
public boolean getBooleanValue() {
String value = getValue();
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("t") ||
value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true")) {
return true;
} else {
return false;
}
}
```

Therefore, "value" should be checked if null before 'equalsIgnoreCase' to avoid Null Pointer Exception.
It would be better like shown below according to your coding style, I think.
```
public boolean getBooleanValue() {
String value = getValue();
        if (value == null)
            return false;

if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("t") ||
value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true")) {
return true;
} else {
return false;
}
}
```
Generated at Fri Apr 19 06:59:33 UTC 2024 using JIRA 189.