New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document GSON StackOverflow and possible solutions #1798

Closed
gintechsystems opened this Issue Nov 18, 2015 · 12 comments

Comments

Projects
None yet
3 participants
@gintechsystems

gintechsystems commented Nov 18, 2015

I have a working RealmObject but when I try to add the following code:

@Ignore
Drawable picDrawable;

The app just keeps looping objects and eventually crashes, is there a way to resolve this? I use this property later in the app but not consistently. The drawable is loaded from a bitmap that is loaded using glide.

@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

11-18 11:32:20.388 24481-24494/com.droid.visneta I/art: Background partial concurrent mark sweep GC freed 2543720(44MB) AllocSpace objects, 22(3MB) LOS objects, 13% free, 103MB/119MB, paused 1.075ms total 232.487ms
11-18 11:32:20.399 24481-24888/com.droid.visneta D/Error: ERR: exClass=java.lang.StackOverflowError
11-18 11:32:20.399 24481-24888/com.droid.visneta D/Error: ERR: exMsg=stack size 1038KB
11-18 11:32:20.399 24481-24888/com.droid.visneta D/Error: ERR: file=$Gson$Types.java
11-18 11:32:20.399 24481-24888/com.droid.visneta D/Error: ERR: class=com.google.gson.internal.$Gson$Types
11-18 11:32:20.399 24481-24888/com.droid.visneta D/Error: ERR: method=resolve line=374
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error: ERR: stack=java.lang.RuntimeException: An error occurred while executing doInBackground()
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at android.os.AsyncTask$3.done(AsyncTask.java:309)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at java.lang.Thread.run(Thread.java:818)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:  Caused by: java.lang.StackOverflowError: stack size 1038KB
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:374)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:     at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error:   at com.google.gson.internal.$Gson$Types.res
11-18 11:32:20.416 24481-24888/com.droid.visneta D/Error: ERR: TOTAL BYTES WRITTEN: 2523804
11-18 11:32:20.416 24481-24888/com.droid.visneta E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 2523888)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime: Error reporting crash
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime: android.os.TransactionTooLargeException: data parcel size 2523888 bytes
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at android.os.BinderProxy.transactNative(Native Method)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at android.os.BinderProxy.transact(Binder.java:503)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4425)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
11-18 11:32:20.417 24481-24888/com.droid.visneta E/AndroidRuntime:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
11-18 11:32:20.417 24481-24888/com.droid.visneta I/Process: Sending signal. PID: 24481 SIG: 9
@cmelchior

This comment has been minimized.

Contributor

cmelchior commented Nov 18, 2015

The error seems to be caused by GSON not being configured properly. Have you followed the guideline described here: https://realm.io/docs/java/latest/#gson ?

@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

Here is my GSON code:

visnetawrap.gsonClient = new GsonBuilder()
                .setExclusionStrategies(new ExclusionStrategy() {
                    @Override
                    public boolean shouldSkipField(FieldAttributes f) {
                        return f.getDeclaringClass().equals(RealmObject.class);
                    }

                    @Override
                    public boolean shouldSkipClass(Class<?> clazz) {
                        return false;
                    }
                })
                .registerTypeAdapter(Date.class, new GsonDateDeserializer())
                .registerTypeAdapter(Double.class, new TypeAdapter<Double>() {
                    @Override
                    public void write(JsonWriter out, Double value) throws IOException {
                        if (value == null) {
                            out.nullValue();
                            return;
                        }
                        out.value(value);
                    }

                    @Override
                    public Double read(JsonReader in) throws IOException {
                        if (in.peek() == JsonToken.NULL) {
                            in.nextNull();
                            return null;
                        }
                        String stringValue = in.nextString();
                        try {
                            return Double.valueOf(stringValue);
                        } catch (NumberFormatException e) {
                            return null;
                        }
                    }
                })
                .create();
@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

Yeah, it looks like I am following the guidelines unless I am missing something. Here is how I am capturing the objects into realm. Note I am using a for loop because when I try to do just fromJson I get a memory error.

Realm realmThread = Realm.getDefaultInstance();

                List<ConvoMsgObject> convoUsersList = new ArrayList<>();
                for (int i = 0; i < convoUsers.size(); i++) {
                    if (!visnetawrap.isUserLoggedIn) {
                        return null;
                    }
                    ConvoMsgObject convoUser = visnetawrap.gsonClient.fromJson(convoUsers.get(i).toString(), ConvoMsgObject.class);
                    convoUsersList.add(convoUser);
                }
                realmThread.beginTransaction();
                realmThread.copyToRealmOrUpdate(convoUsersList);
                realmThread.commitTransaction();

                realmThread.close();
@cmelchior

This comment has been minimized.

Contributor

cmelchior commented Nov 18, 2015

Maybe the Drawable class has some of the same inheritance problems that RealmObject has. It is unfortunately not possible to tell from the stack trace. Have you tried adding it to the shouldSkipField method?

@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

Let me try, picDrawable is just a Drawable, I did not create a custom class for it.

@cmelchior

This comment has been minimized.

Contributor

cmelchior commented Nov 18, 2015

Ah yes. Sorry.

public boolean shouldSkipField(FieldAttributes f) {
  return f.getDeclaringClass().equals(RealmObject.class) || f.getDeclaringClass().equals(Drawable.class);
}

Something like the above should test it.

@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

That seemed to work, thank you!

@cmelchior

This comment has been minimized.

Contributor

cmelchior commented Nov 18, 2015

No problem. Sounds like something we want to add to our docs, as others might run into this issue as well.

@cmelchior cmelchior changed the title from @Ignore causing TransactionTooLargeException to Document GSON StackOverflow and possible solutions Nov 18, 2015

@gintechsystems

This comment has been minimized.

gintechsystems commented Nov 18, 2015

I agree.

@bmunkholm

This comment has been minimized.

Contributor

bmunkholm commented Nov 30, 2015

.

@cmelchior

This comment has been minimized.

Contributor

cmelchior commented Dec 11, 2015

@cmelchior cmelchior closed this Dec 11, 2015

@cmelchior cmelchior removed the P1 label Dec 11, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment