Skip to content

Commit

Permalink
#429 : Raise CodecExpection if 2 node with same Id in json decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed May 30, 2018
1 parent 0ddeebd commit caa23c0
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,21 @@ private static Map<Integer, LwM2mResource> extractLwM2mResources(Collection<Json
multiResource = new HashMap<>();
multiResourceMap.put(resourcePath, multiResource);
}
multiResource.put(nodePath.getResourceInstanceId(), resourceElt);
JsonArrayEntry prevouisResInstance = multiResource.put(nodePath.getResourceInstanceId(), resourceElt);
if (prevouisResInstance != null) {
throw new CodecException("2 RESOURCE_INSTANCE (%s,%s) with the same identifier %d for path %s",
prevouisResInstance, resourceElt, nodePath.getResourceInstanceId(), nodePath);
}
} else if (nodePath.isResource()) {
// Single resource
Type expectedType = getResourceType(nodePath, model, resourceElt);
LwM2mResource res = LwM2mSingleResource.newResource(nodePath.getResourceId(),
parseJsonValue(resourceElt.getResourceValue(), expectedType, nodePath), expectedType);
lwM2mResourceMap.put(nodePath.getResourceId(), res);
LwM2mResource previousRes = lwM2mResourceMap.put(nodePath.getResourceId(), res);
if (previousRes != null) {
throw new CodecException("2 RESOURCE (%s,%s) with the same identifier %d for path %s", previousRes,
res, res.getId(), nodePath);
}
} else {
throw new CodecException(
"Invalid path [%s] for resource, it should be a resource or a resource instance path",
Expand All @@ -338,7 +346,11 @@ private static Map<Integer, LwM2mResource> extractLwM2mResources(Collection<Json
}
LwM2mResource resource = LwM2mMultipleResource.newResource(resourcePath.getResourceId(), values,
expectedType);
lwM2mResourceMap.put(resourcePath.getResourceId(), resource);
LwM2mResource previousRes = lwM2mResourceMap.put(resourcePath.getResourceId(), resource);
if (previousRes != null) {
throw new CodecException("2 RESOURCE (%s,%s) with the same identifier %d for path %s", previousRes,
resource, resource.getId(), resourcePath);
}
}
}

Expand Down

0 comments on commit caa23c0

Please sign in to comment.