ONOS-4033 - 500 error when ethType is not specified
Change-Id: Ib2c440450abf94b9e93f7bdf59f9e5b1109c977f
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java b/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java
index 2e01017..f82bd0d 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java
@@ -107,12 +107,13 @@
private class EthTypeDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
+ JsonNode ethTypeNode = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
+ CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE);
int ethType;
- if (json.get(CriterionCodec.ETH_TYPE).isInt()) {
- ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
- CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt();
+ if (ethTypeNode.isInt()) {
+ ethType = ethTypeNode.asInt();
} else {
- ethType = Integer.decode(json.get(CriterionCodec.ETH_TYPE).textValue());
+ ethType = Integer.decode(ethTypeNode.textValue());
}
return Criteria.matchEthType(ethType);
}