JetS3t fails to get LastModifiedDate for existing S3 object in Java 8 but succeeds in Java 7.
package JsTest
import org.jets3t.service.S3Service;
import org.jets3t.service.ServiceException;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.model.S3Object;
import org.jets3t.service.security.AWSCredentials;
public class Jetsettester {
public static void main(String[] args) {
String awsAccessKey = "<access_key>";
String awsSecretKey = "<secret>";
AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
S3Service s3Service = new RestS3Service(awsCredentials);
try {
S3Object objectDetailsOnly = (S3Object) s3Service.getObjectDetails("ENTER_BUCKET_NAME", "EXISTING_SAMPLE_KEY.TXT");
Object md = objectDetailsOnly.getMetadata("Last-Modified"); // Object type is 'String' in Java 8 - and 'Date' in Java 7
Date dt = objectDetailsOnly.getLastModifiedDate(); // Hence, raises ClassCastException only in Java 8 . In Java 7 - it is correct Date class
} catch (ServiceException e) {
e.printStackTrace();
}
}
}
I think there are two header values - one for 'Last-Modified' and other for lowercase 'last-modified' but I dont know more than that. Can someone help?
This was a bug in JetS3t 0.9.3
. I raised the bug and James Murty graciously fixed it last year in release 0.9.4
Posting it here in case anyone else experiences it.
details bitbucket bug link for jets3t