Skip to content

Commit 2e5df7d

Browse files
committed
Print warning if redundant state is set in Asset.Builder
1 parent 83b40f7 commit 2e5df7d

File tree

1 file changed

+11
-0
lines changed
  • skygear/src/main/java/io/skygear/skygear

1 file changed

+11
-0
lines changed

skygear/src/main/java/io/skygear/skygear/Asset.java

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.Context;
2222
import android.net.Uri;
2323
import android.os.ParcelFileDescriptor;
24+
import android.util.Log;
2425

2526
import org.json.JSONException;
2627
import org.json.JSONObject;
@@ -33,6 +34,7 @@
3334
* The Skygear Asset Model.
3435
*/
3536
public class Asset {
37+
private static final String TAG = "Skygear SDK";
3638

3739
/**
3840
* The Name.
@@ -248,6 +250,7 @@ private Asset buildFromInputStream() {
248250

249251
private Asset buildFromByteArray() {
250252
ensureStateIsNonNull(this.mimeType, "MimeType");
253+
warnRedundantStateIfNeeded(this.size, "Size", "data");
251254

252255
long size = this.data.length;
253256
InputStream inputStream = new ByteArrayInputStream(this.data);
@@ -257,6 +260,8 @@ private Asset buildFromByteArray() {
257260

258261
private Asset buildFromUri() {
259262
ensureStateIsNonNull(this.context, "Context");
263+
warnRedundantStateIfNeeded(this.mimeType, "MimeType", "uri");
264+
warnRedundantStateIfNeeded(this.size, "Size", "uri");
260265

261266
ContentResolver contentResolver = context.getContentResolver();
262267
InputStream inputStream;
@@ -280,5 +285,11 @@ private static void ensureStateIsNonNull(Object state, String name) {
280285
throw new IllegalStateException(name + " must be set first");
281286
}
282287
}
288+
289+
private static void warnRedundantStateIfNeeded(Object state, String name, String context) {
290+
if (state != null) {
291+
Log.w(TAG, name + " would be ignored when using " + context + " as data source");
292+
}
293+
}
283294
}
284295
}

0 commit comments

Comments
 (0)