6

从 UiLifecycleHelper 收到一个奇怪的 StackOverflow 错误。看起来它正在尝试加载序列化对象,但随后 ObjectInputStream 运行到递归循环中,可能是由于数据损坏。它只发生在 onCreate 方法中。这是堆栈跟踪

更新

StackOverflowError 实际上也发生在 onSaveInstance 状态,但在 ObjectStream 写入中循环。我们确实只有 4 个崩溃日志显示了这一点,在 onCreate 中读取时有 49 个崩溃日志。这是正在使用的代码:

uiHelper 在它的所有预期方法中被调用,onCreate、onResume、onPause、onSaveInstanceState、onDestroy 完全没有偏离文档。使用的所有其他 Facebook 代码如下所示。

//onClick facebook button
private void facebook() {
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        Log.v("W", "Already have session");
        publishog(session);
    } else {

        Session.openActiveSession(WWhisperActivity.this, true, callback);
    }
}

private void onSessionStateChange(Session session, SessionState state,
        Exception e) {
    if (e != null && !e.getLocalizedMessage().contains("user denied")) {
        BugSenseHandler.sendException(e);
    }
    if (state.equals(SessionState.OPENING)) {
        Log.v("W", "Session opening state");
    } else if (state.equals(SessionState.CREATED)
            || state.equals(SessionState.CREATED_TOKEN_LOADED)) {
        Log.v("W", "Session created state");
    }
    if (state.isOpened()) {
        Log.v("W", "Open session");
        if (!session.getPermissions().contains("publish_actions")) {
            Log.v("W", "Getting publish permission");
            Session.NewPermissionsRequest r = new Session.NewPermissionsRequest(
                    this, Arrays.asList("publish_actions"));
            session.requestNewPublishPermissions(r);
        } else {
            Log.v("W", "Session opened, publishing og");
            publishog(session);
        }
    } else if (state.equals(SessionState.CLOSED)
            || state.equals(SessionState.CLOSED_LOGIN_FAILED)) {
        Log.v("W", "Session not open");
        session.closeAndClearTokenInformation();
        if (state.equals(SessionState.CLOSED_LOGIN_FAILED)) {
            if (e == null || !e.getLocalizedMessage().contains("abort")
                    && !e.getLocalizedMessage().contains("user denied"))
                Session.openActiveSession(this, true, callback);
        }
    }
}

private void publishog(Session session) {
    Log.v("W", "Publishing OG");
    WObject wo = GraphObject.Factory.create(WObject.class);
    wo.setId(w.wid);
    wo.setUrl(shorturl);
    WOGShare ws = GraphObject.Factory.create(WOGShare.class);
    ws.setWhisper(shorturl);
    com.facebook.Request.executePostRequestAsync(session,
            "me/whisper_app:share", ws,
            new com.facebook.Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    pd.dismiss();
                    if (response.getError() != null) {

                    } else {

                    }

                }

            });
}

崩溃日志:

java.lang.StackOverflowError
1at java.lang.ThreadLocal.get(ThreadLocal.java:65)
2at java.io.ObjectStreamClass.getCache(ObjectStreamClass.java:1093)
3at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1066)
4at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:1037)
5at java.io.ObjectStreamClass.createClassDesc(ObjectStreamClass.java:248)
6at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1069)
7at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:1037)
8at java.io.ObjectStreamClass.createClassDesc(ObjectStreamClass.java:248)
9at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1069)
10at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:1037)
11at java.io.ObjectStreamClass.createClassDesc(ObjectStreamClass.java:248)
12at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1069)
13at java.io.ObjectInputStream.verifyAndInit(ObjectInputStream.java:2375)
14at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1662)
15at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
16at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1803)
17at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
18at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
19at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
20at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
21at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
22at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
23at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
24at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
25at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
26at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
27at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
28at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
29at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
30at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
31at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
32at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
33at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
34at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
35at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
36at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
37at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
38at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
39at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
40at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
41at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
42at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
43at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
44at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
45at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
46at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
47at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
48at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
49at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
50at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
51at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
52at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
53at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
54at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
55at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
56at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
57at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
58at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
59at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
60at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
61at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
62at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
63at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
64at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
65at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
66at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
67at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
68at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
69at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
70at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
71at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
72at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
73at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
74at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
75at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
76at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
77at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
78at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
79at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
325at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
326at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
327at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
328at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
329at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
330at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
331at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
332at com.facebook.Session.restoreSession(Session.java:701)
333at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:70)
334at sh.whisper.WWhisperActivity.onCreate(WWhisperActivity.java:279)
335at android.app.Activity.performCreate(Activity.java:5160)
336at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
337at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
338at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
339at android.app.ActivityThread.access$700(ActivityThread.java:143)
340at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
341at android.os.Handler.dispatchMessage(Handler.java:99)
342at android.os.Looper.loop(Looper.java:137)
343at android.app.ActivityThread.main(ActivityThread.java:4953)
344at java.lang.reflect.Method.invokeNative(Native Method)
345at java.lang.reflect.Method.invoke(Method.java:511)
346at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
347at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)

348at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

参数和局部变量在堆栈上分配(对象存在于堆上的引用类型和引用该对象的变量)。堆栈通常位于地址空间的上端,当它用完时,它会朝向地址空间的底部(即朝向零)。

gui 编程可以生成间接递归。例如,您的应用程序可能正在处理绘画消息,并且在处理它们时可能会调用一个函数,该函数会导致系统发送另一条绘画消息。在这里,您没有明确称呼自己,但 OS/VM 已经为您完成了。

我之前也遇到过同样的错误。做一件事只是删除类正下方的任何初始化并将其移动到内部onCreate()onResume().

于 2013-06-13T18:05:13.063 回答