This code contains a possible null pointer dereference. Double-check the code to ensure that the concerned variable always has a non-null value when accessed.
In the example below, if someCondition
is true, it is possible for value
to be null when it reaches the assignment
of valLen
.
String value = "something";
if (someCondition) {
value = null;
}
// ...
int valLen = value.length; // Null pointer exception!
Check for null before you use the value at the vulnerable point in code.
int valLen = value != null ? value.length : 0;
If value
was instead never intended to be null, consider changing the preceding logic to ensure that value
is at
least set to a safe default wherever possible:
if (someCondition) {
value = "";
}
int valLen = value.length; // No exception thrown.