Skip to content

Commit 59ce640

Browse files
authored
fix: set transferUtilityOptions to default in case of deserialization exception (#3296)
1 parent 493ce15 commit 59ce640

File tree

1 file changed

+21
-14
lines changed
  • aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility

1 file changed

+21
-14
lines changed

aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferRecord.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import com.google.gson.Gson;
3030

31+
import com.google.gson.JsonSyntaxException;
3132
import java.io.File;
3233
import java.util.Map;
3334
import java.util.concurrent.ExecutionException;
@@ -156,12 +157,18 @@ public void updateFromDB(Cursor c) {
156157
this.cannedAcl = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_CANNED_ACL));
157158
this.headerStorageClass = c
158159
.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_STORAGE_CLASS));
159-
this.transferUtilityOptions = gson.fromJson(c.getString(c
160-
.getColumnIndexOrThrow(TransferTable.COLUMN_TRANSFER_UTILITY_OPTIONS)), TransferUtilityOptions.class);
160+
String options = c.getString(c
161+
.getColumnIndexOrThrow(TransferTable.COLUMN_TRANSFER_UTILITY_OPTIONS));
162+
try {
163+
this.transferUtilityOptions = gson.fromJson(options, TransferUtilityOptions.class);
164+
} catch (JsonSyntaxException jsonSyntaxException) {
165+
LOGGER.error(String.format("Failed to deserialize: %s, setting to default", options), jsonSyntaxException);
166+
this.transferUtilityOptions = new TransferUtilityOptions();
167+
}
161168
}
162169

163170
/**
164-
* Start a new transfer when
171+
* Start a new transfer when
165172
* 1) there is no existing transfer for the same transfer record
166173
* 2) the transfer is not completed
167174
* 3) the preferred network is available
@@ -172,12 +179,12 @@ public void updateFromDB(Cursor c) {
172179
* @param connManager the android network connectivity manager
173180
* @return Whether the task is running.
174181
*/
175-
public boolean start(final AmazonS3 s3,
176-
final TransferDBUtil dbUtil,
182+
public boolean start(final AmazonS3 s3,
183+
final TransferDBUtil dbUtil,
177184
final TransferStatusUpdater updater,
178185
final ConnectivityManager connManager) {
179-
if (!isRunning() &&
180-
checkIsReadyToRun() &&
186+
if (!isRunning() &&
187+
checkIsReadyToRun() &&
181188
checkPreferredNetworkAvailability(updater, connManager)) {
182189
if (type.equals(TransferType.DOWNLOAD)) {
183190
submittedTask = TransferThreadPool
@@ -222,10 +229,10 @@ public boolean pause(final AmazonS3 s3,
222229
* @return true if the transfer is running and is paused successfully, false
223230
* otherwise
224231
*/
225-
boolean pauseIfRequiredForNetworkInterruption(final AmazonS3 s3,
232+
boolean pauseIfRequiredForNetworkInterruption(final AmazonS3 s3,
226233
final TransferStatusUpdater updater,
227234
final ConnectivityManager connManager) {
228-
// Check if the transfer needs to be paused
235+
// Check if the transfer needs to be paused
229236
if (!checkPreferredNetworkAvailability(updater, connManager)) {
230237
// the preferred network is not available. pause the transfer.
231238
if (!isFinalState(state)) {
@@ -241,13 +248,13 @@ boolean pauseIfRequiredForNetworkInterruption(final AmazonS3 s3,
241248

242249
/**
243250
* Cancels a running transfer.
244-
*
251+
*
245252
* @param s3 s3 instance
246253
* @param updater status updater
247254
* @return true if the transfer is running and is canceled successfully,
248255
* false otherwise
249256
*/
250-
public boolean cancel(final AmazonS3 s3,
257+
public boolean cancel(final AmazonS3 s3,
251258
final TransferStatusUpdater updater) {
252259
if (!isFinalState(state)) {
253260
// Update the state to PENDING_CANCEL in the TransferStatusUpdater
@@ -266,8 +273,8 @@ public void run() {
266273
try {
267274
// abort the multi part upload operation
268275
s3.abortMultipartUpload(
269-
new AbortMultipartUploadRequest(bucketName,
270-
key,
276+
new AbortMultipartUploadRequest(bucketName,
277+
key,
271278
multipartId));
272279
LOGGER.debug("Successfully clean up multipart upload: " + id);
273280
} catch (final AmazonClientException e) {
@@ -360,7 +367,7 @@ public String toString() {
360367
protected boolean checkPreferredNetworkAvailability(final TransferStatusUpdater updater,
361368
final ConnectivityManager connManager) {
362369

363-
if (connManager == null) {
370+
if (connManager == null) {
364371
// Unable to get the details of the network, we will start the transfer.
365372
return true;
366373
}

0 commit comments

Comments
 (0)