NumberFormatException in AbstractS3ResponseHandler::populateObjectMetadata with GET Object request
For AWS SDK for Java version 1.4.1:
In the documentation it shows that the response from the GET Object has a Expires response header of the form:
Expires: Thu, 01 Dec 1994 16:00:00 GMT
This matches what the HTTP RFC2616 specifies for this field.
However, in the routine AbstractS3ResponseHandler::populateObjectMetadata, it is expecting the Expires value to be an integer; thus throws a warning exception of NumberFormatException.
The following is the current code lines from that module:
} else if (key.equals(Headers.EXPIRES)) {
try {
metadata.setExpirationTime(new Date(Long.parseLong(header.getValue())));
} catch (NumberFormatException pe) {
log.warn("Unable to parse expiration time: " + header.getValue(), pe);
}
Based on the API documentation and the HTTP standard, the code should really be:
} else if (key.equals(Headers.EXPIRES)) {
try {
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
metadata.setExpirationTime(df.parse(header.getValue()));
} catch (ParseException pe) {
log.warn("Unable to parse expiration time:" + header.getValue(), pe);
}
Some more data. If doing the following Java lines with the AWS SDK, it will reproduce the problem:
GetObjectRequest objectRequest = new GetObjectRequest(bucketName, key).withResponseHeaders(new ResponseHeaderOverrides().withExpires("Tue, 25 Mar 2013 15:04:07 GMT"));
S3Object object = s3Client.getObject(objectRequest);
Note that the following commented out line does not throw the exception, but according to the HTTP Standard, this is not valid value.
// GetObjectRequest objectRequest = new GetObjectRequest(bucketName, key).withResponseHeaders(new ResponseHeaderOverrides().withExpires("0"));
Thank you very much for pointing this out!
I have noticed that issue, we resolve it in a slight different way, (we have the DateUtils class). It will be included in the next release.
thanks again for your effort!
Hi, we have cleared up some of the confusion with the expires headers in the 1.4.5 release - http://aws.amazon.com/releasenotes/Java/1162337172145650