Skip to content

Commit

Permalink
Throw on parsing invalid date value
Browse files Browse the repository at this point in the history
  • Loading branch information
Renaud Paquay committed Nov 19, 2011
1 parent dfe901e commit 323b733
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private Builder addPutBlobHeaders(CreateBlobOptions options, Builder builder) {
private GetBlobPropertiesResult getBlobPropertiesResultFromResponse(ClientResponse response) {
// Properties
BlobProperties properties = new BlobProperties();
properties.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
properties.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
properties.setBlobType(response.getHeaders().getFirst("x-ms-blob-type"));
properties.setLeaseStatus(response.getHeaders().getFirst("x-ms-lease-status"));

Expand Down Expand Up @@ -323,7 +323,7 @@ private GetContainerPropertiesResult getContainerPropertiesImpl(String container

GetContainerPropertiesResult properties = new GetContainerPropertiesResult();
properties.setEtag(response.getHeaders().getFirst("ETag"));
properties.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
properties.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
properties.setMetadata(getMetadataFromHeaders(response));

return properties;
Expand All @@ -347,7 +347,7 @@ public GetContainerACLResult getContainerACL(String container, BlobServiceOption
acl.setSignedIdentifiers(si.getSignedIdentifiers());
acl.setPublicAccess(response.getHeaders().getFirst("x-ms-blob-public-access"));
acl.setEtag(response.getHeaders().getFirst("ETag"));
acl.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
acl.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

GetContainerACLResult result = new GetContainerACLResult();
result.setValue(acl);
Expand Down Expand Up @@ -493,7 +493,7 @@ public GetBlobMetadataResult getBlobMetadata(String container, String blob, GetB

GetBlobMetadataResult properties = new GetBlobMetadataResult();
properties.setEtag(response.getHeaders().getFirst("ETag"));
properties.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
properties.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
properties.setMetadata(getMetadataFromHeaders(response));

return properties;
Expand Down Expand Up @@ -525,7 +525,7 @@ public SetBlobPropertiesResult setBlobProperties(String container, String blob,
SetBlobPropertiesResult result = new SetBlobPropertiesResult();

result.setEtag(response.getHeaders().getFirst("ETag"));
result.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
if (response.getHeaders().getFirst("x-ms-blob-sequence-number") != null) {
result.setSequenceNumber(Long.parseLong(response.getHeaders().getFirst("x-ms-blob-sequence-number")));
}
Expand All @@ -552,7 +552,7 @@ public SetBlobMetadataResult setBlobMetadata(String container, String blob, Hash

SetBlobMetadataResult result = new SetBlobMetadataResult();
result.setEtag(response.getHeaders().getFirst("ETag"));
result.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
return result;
}

Expand Down Expand Up @@ -616,7 +616,7 @@ public CreateBlobSnapshotResult createBlobSnapshot(String container, String blob
CreateBlobSnapshotResult blobSnapshot = new CreateBlobSnapshotResult();
blobSnapshot.setEtag(response.getHeaders().getFirst("ETag"));
blobSnapshot.setSnapshot(response.getHeaders().getFirst("x-ms-snapshot"));
blobSnapshot.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
blobSnapshot.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

return blobSnapshot;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ private CreateBlobPagesResult updatePageBlobPagesImpl(String action, String cont

CreateBlobPagesResult result = new CreateBlobPagesResult();
result.setEtag(response.getHeaders().getFirst("ETag"));
result.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));
result.setContentMD5(response.getHeaders().getFirst("Content-MD5"));
result.setSequenceNumber(Long.parseLong(response.getHeaders().getFirst("x-ms-blob-sequence-number")));

Expand All @@ -759,7 +759,7 @@ public ListBlobRegionsResult listBlobRegions(String container, String blob, List
ListBlobRegionsResult result = response.getEntity(ListBlobRegionsResult.class);
result.setEtag(response.getHeaders().getFirst("ETag"));
result.setContentLength(Long.parseLong(response.getHeaders().getFirst("x-ms-blob-content-length")));
result.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

return result;
}
Expand Down Expand Up @@ -822,7 +822,7 @@ public ListBlobBlocksResult listBlobBlocks(String container, String blob, ListBl
result.setEtag(response.getHeaders().getFirst("ETag"));
result.setContentType(response.getHeaders().getFirst("Content-Type"));
result.setContentLength(Long.parseLong(response.getHeaders().getFirst("x-ms-blob-content-length")));
result.setLastModified(dateMapper.parseNoThrow(response.getHeaders().getFirst("Last-Modified")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ public String format(Date date) {
return getFormat().format(date);
}

public Date parse(String date) throws ParseException {
return getFormat().parse(date);
}

public Date parseNoThrow(String date) {
public Date parse(String date) {
try {
return parse(date);
return getFormat().parse(date);
}
catch (ParseException e) {
return null;
String msg = String.format("The value \"%s\" is not a valid RFC 1123 date.", date);
throw new IllegalArgumentException(msg, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public UpdateMessageResult updateMessage(String queue, String messageId, String

UpdateMessageResult result = new UpdateMessageResult();
result.setPopReceipt(response.getHeaders().getFirst("x-ms-popreceipt"));
result.setTimeNextVisible(dateMapper.parseNoThrow(response.getHeaders().getFirst("x-ms-time-next-visible")));
result.setTimeNextVisible(dateMapper.parse(response.getHeaders().getFirst("x-ms-time-next-visible")));
return result;
}

Expand Down

0 comments on commit 323b733

Please sign in to comment.