Skip to content

Commit d9231da

Browse files
authored
Don't return incorrect date format instance (#3576)
1 parent 62a5fb4 commit d9231da

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

aws-android-sdk-core/src/main/java/com/amazonaws/transform/SimpleTypeJsonUnmarshallers.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public static ByteJsonUnmarshaller getInstance() {
249249
*/
250250
public static class DateJsonUnmarshaller implements Unmarshaller<Date, JsonUnmarshallerContext> {
251251
private static final int DATE_MULTIPLIER = 1000;
252-
private final TimestampFormat format;
252+
final TimestampFormat format;
253253

254254
private DateJsonUnmarshaller(TimestampFormat format) {
255255
this.format = format;
@@ -286,10 +286,7 @@ public Date unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Excep
286286
* @return the instance.
287287
*/
288288
public static DateJsonUnmarshaller getInstance() {
289-
if (instance == null) {
290-
instance = new DateJsonUnmarshaller(TimestampFormat.UNIX_TIMESTAMP);
291-
}
292-
return instance;
289+
return getInstance(TimestampFormat.UNIX_TIMESTAMP);
293290
}
294291

295292
/**

aws-android-sdk-core/src/test/java/com/amazonaws/transform/SimpleTypeJsonUnmarshallerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ public void testDateRfc822JsonUnmarshaller() throws Exception {
256256
assertEquals(unmarshalledDate.getTime(), date.getTime());
257257
}
258258

259+
@Test
260+
public void defaultFunctionAlwaysReturnsUnixTimestampUnmarshaller() {
261+
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller first =
262+
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller.getInstance(TimestampFormat.ISO_8601);
263+
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller second =
264+
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller.getInstance();
265+
assertEquals(TimestampFormat.UNIX_TIMESTAMP, second.format);
266+
}
267+
259268
@Test
260269
public void testDoubleJsonUnmarshaller() throws Exception {
261270
Double dub = new Double(5.5);

0 commit comments

Comments
 (0)