Reputation: 21
One of my codes after sonar analysis shows the error Change this condition so that it does not always evaluate to "false"
for below code.
The condition that always evaluate to false is if (value != null)
, as per Sonar. But I don't think sonar is right here. Can you please help me to resolve this since my sonar is failing due to this?
Please find the code here:
protected Message generateProtoMessage(Object document, Message.Builder builder) {
Descriptor descriptor = builder.getDescriptorForType();
for (FieldDescriptor protoField : descriptor.getFields()) {
Object value = null;
if (PROTO_JAVA_TYPES.contains(protoField.getJavaType())) {
value = getFieldValueByMethod(document, protoField);
} else if (JavaType.MESSAGE.equals(protoField.getJavaType())) {
if(protoField.isMapField()){
populateValueForMapType(document, protoField, builder);
} else {
value = getValueForMessageType(document, protoField);
}
} else if (JavaType.ENUM.equals(protoField.getJavaType())) {
value = getFieldValueForEnum(document, protoField);
}
if (value != null) builder.setField(protoField, value);
}
return builder.build();
}
Upvotes: 0
Views: 133