Merge "Ensure thread-safety of SimpleDateFormat" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
78552a888a
@@ -31,6 +31,7 @@ import android.system.OsConstants;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
@@ -586,7 +587,9 @@ public class ExifInterface {
|
|||||||
private static final int WEBP_CHUNK_SIZE_BYTE_LENGTH = 4;
|
private static final int WEBP_CHUNK_SIZE_BYTE_LENGTH = 4;
|
||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
@GuardedBy("sFormatter")
|
||||||
private static SimpleDateFormat sFormatter;
|
private static SimpleDateFormat sFormatter;
|
||||||
|
@GuardedBy("sFormatterTz")
|
||||||
private static SimpleDateFormat sFormatterTz;
|
private static SimpleDateFormat sFormatterTz;
|
||||||
|
|
||||||
// See Exchangeable image file format for digital still cameras: Exif version 2.2.
|
// See Exchangeable image file format for digital still cameras: Exif version 2.2.
|
||||||
@@ -2426,13 +2429,18 @@ public class ExifInterface {
|
|||||||
try {
|
try {
|
||||||
// The exif field is in local time. Parsing it as if it is UTC will yield time
|
// The exif field is in local time. Parsing it as if it is UTC will yield time
|
||||||
// since 1/1/1970 local time
|
// since 1/1/1970 local time
|
||||||
Date datetime = sFormatter.parse(dateTimeString, pos);
|
Date datetime;
|
||||||
|
synchronized (sFormatter) {
|
||||||
|
datetime = sFormatter.parse(dateTimeString, pos);
|
||||||
|
}
|
||||||
|
|
||||||
if (offsetString != null) {
|
if (offsetString != null) {
|
||||||
dateTimeString = dateTimeString + " " + offsetString;
|
dateTimeString = dateTimeString + " " + offsetString;
|
||||||
ParsePosition position = new ParsePosition(0);
|
ParsePosition position = new ParsePosition(0);
|
||||||
|
synchronized (sFormatterTz) {
|
||||||
datetime = sFormatterTz.parse(dateTimeString, position);
|
datetime = sFormatterTz.parse(dateTimeString, position);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (datetime == null) return -1;
|
if (datetime == null) return -1;
|
||||||
long msecs = datetime.getTime();
|
long msecs = datetime.getTime();
|
||||||
@@ -2473,7 +2481,10 @@ public class ExifInterface {
|
|||||||
|
|
||||||
ParsePosition pos = new ParsePosition(0);
|
ParsePosition pos = new ParsePosition(0);
|
||||||
try {
|
try {
|
||||||
Date datetime = sFormatter.parse(dateTimeString, pos);
|
final Date datetime;
|
||||||
|
synchronized (sFormatter) {
|
||||||
|
datetime = sFormatter.parse(dateTimeString, pos);
|
||||||
|
}
|
||||||
if (datetime == null) return -1;
|
if (datetime == null) return -1;
|
||||||
return datetime.getTime();
|
return datetime.getTime();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user