Reputation: 132
I have the following code:
Map<BigInteger, AttributeValue> values = getParameters(elementHandler);
AttributeValue value = values.get(attrID);
AttributeValue auxValue = null;
if (auxAttrID != null)
auxValue = values.get(auxAttrID);
try {
if (value == null) {
// some code here
}
if (value != null) {
assert (value != null) : "value is null";
if (value.getValue() == null ) {
// some code here
} else if (auxAttrID != null && auxValue != null) {
// some code here
}
}
} catch (Exception e) {
log.error("Error at getting attribute value (attr#" + attrID + ", auxAttrId#" + auxAttrID + ")", e);
}
return value;
}
It produces NullPointerException
at line
if (value.getValue() == null )
right after assertion.
AttributeValue
is a simple POJO class. Why this happens and how can I fix it?
Upvotes: 2
Views: 113
Reputation: 5619
It produces NullPointerException at line
if (value.getValue() == null )
if (value != null) {
//...
if (value.getValue() == null ) {
//....
The above if
condition states that, value
is not NULL
when you are invoking value.getValue()
. Still you are getting NullPointerException
for value.getValue()
means the exception is coming from method getValue()
(e.g you are trying to access any class attributes with a NULL
object etc).
Edit your question with the implementation of getValue()
.
Use getStackTrace() to find out where the problem occurs. Read this for more information.
Upvotes: 1