Last Comment Bug 737445 - java.lang.ClassCastException: java.lang.String at org.mozilla.gecko.FormAssistPopup$AutoCompleteListAdapter.populateSuggestionsList(FormAssistPopup.java)
: java.lang.ClassCastException: java.lang.String at org.mozilla.gecko.FormAssis...
Status: RESOLVED FIXED
[native-crash]
: crash
Product: Firefox for Android
Classification: Client Software
Component: General (show other bugs)
: 13 Branch
: ARM Android
: -- critical (vote)
: Firefox 14
Assigned To: :Margaret Leibovic
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-20 08:41 PDT by Scoobidiver (away)
Modified: 2012-03-24 07:52 PDT (History)
5 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed
fixed


Attachments
patch (1.48 KB, patch)
2012-03-20 11:53 PDT, :Margaret Leibovic
mark.finkle: review+
akeybl: approval‑mozilla‑aurora+
Details | Diff | Review

Description Scoobidiver (away) 2012-03-20 08:41:16 PDT
There are two crashes from the same user in 13.0a2/20120315: bp-c54ff8bc-9f80-4a18-9e40-709172120319, bp-b39b8752-72e7-4064-9a71-669782120319.

java.lang.ClassCastException: java.lang.String
	at org.mozilla.gecko.FormAssistPopup$AutoCompleteListAdapter.populateSuggestionsList(FormAssistPopup.java:286)
	at org.mozilla.gecko.FormAssistPopup.showAutoCompleteSuggestions(FormAssistPopup.java:158)
	at org.mozilla.gecko.FormAssistPopup.access$100(FormAssistPopup.java:64)
	at org.mozilla.gecko.FormAssistPopup$2.run(FormAssistPopup.java:132)
	at android.os.Handler.handleCallback(Handler.java:587)
	at android.os.Handler.dispatchMessage(Handler.java:92)
	at android.os.Looper.loop(Looper.java:130)
	at android.app.ActivityThread.main(ActivityThread.java:3687)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:507)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
	at dalvik.system.NativeStart.main(Native Method)

More reports at:
https://crash-stats.mozilla.com/report/list?signature=java.lang.ClassCastException%3A+java.lang.String+at+org.mozilla.gecko.FormAssistPopup%24AutoCompleteListAdapter.populateSuggestionsList%28FormAssistPopup.java%29
Comment 1 Aaron Train [:aaronmt] 2012-03-20 08:46:55 PDT
Seems like an easy fix in populateSuggestionsList();
Comment 2 :Margaret Leibovic 2012-03-20 10:30:46 PDT
(In reply to Aaron Train [:aaronmt] from comment #1)
> Seems like an easy fix in populateSuggestionsList();

What do you think that fix is?

(In reply to Scoobidiver from comment #0)
> java.lang.ClassCastException: java.lang.String

Is this the whole error at this line? I would think it would be something like "java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject" since that's the cast we're doing here. 

If that's the case, that means that suggestions.get(i) is giving us a String that can't be cast to a JSONObject. Suggestions *should* be an array of { label: x, value: y} JSON objects:
http://mxr.mozilla.org/mozilla-central/source/mobile/android/chrome/content/browser.js#3009

I guess the thing to look into would be to make sure we're always sending the right data to java. Since only one user is seeing this crash, maybe some bad data got into the suggestions data and busted the string. I wonder what would happen if you tried putting JSON-like data in datalist suggestions. I would hope that our JSON stringify/parse code would handle this correctly.
Comment 3 :Margaret Leibovic 2012-03-20 10:34:00 PDT
(In reply to Margaret Leibovic [:margaret] from comment #2)
> (In reply to Aaron Train [:aaronmt] from comment #1)
> > Seems like an easy fix in populateSuggestionsList();
> 
> What do you think that fix is?

Oh, I guess we could change line 286 to:

JSONObject suggestion = suggestions.getJSONObject(i);

But then that would just be throwing a JSONException instead of a ClassCastException. This would get rid of the crash, but it might be worth investigating why this problem is happening in the first place.
Comment 4 Scoobidiver (away) 2012-03-20 10:47:41 PDT
(In reply to Margaret Leibovic [:margaret] from comment #2)
> (In reply to Scoobidiver from comment #0)
> > java.lang.ClassCastException: java.lang.String 
> Is this the whole error at this line?
Yes. See the Java Stack Trace field in the two crash reports.
Comment 5 :Margaret Leibovic 2012-03-20 11:53:33 PDT
Created attachment 607649 [details] [diff] [review]
patch

This will prevent a ClassCastException. I'd still like to try to reproduce this problem, but I don't have the time right now. Maybe we can file a follow-up in case someone has time to try to create some bad suggestion strings?

Even though we could still encounter a JSONException, the only thing that would happen is that the suggestion wouldn't get added to the list, and that isn't the end of the world, especially if there was some weird issue causing the suggestion to be formatted incorrectly.
Comment 6 Mark Finkle (:mfinkle) (use needinfo?) 2012-03-20 14:20:52 PDT
Comment on attachment 607649 [details] [diff] [review]
patch

So this bug would eventually re-appear as a "no autocomplete suggestions appear" bug? We at least have code to handle the exception and stop the crash, which is important.
Comment 7 :Margaret Leibovic 2012-03-21 08:32:59 PDT
(In reply to Mark Finkle (:mfinkle) from comment #6)

> So this bug would eventually re-appear as a "no autocomplete suggestions
> appear" bug?

Yeah, that would be the symptom if this problem re-appears. And in that case we would have the actual website/profile to debug this problem.

https://hg.mozilla.org/integration/mozilla-inbound/rev/e0c8bf206124
Comment 8 Marco Bonardo [::mak] 2012-03-22 06:23:23 PDT
https://hg.mozilla.org/mozilla-central/rev/e0c8bf206124
Comment 9 :Margaret Leibovic 2012-03-22 10:20:11 PDT
Comment on attachment 607649 [details] [diff] [review]
patch

[Approval Request Comment]
Mobile only. Crash fix.
Comment 10 Alex Keybl [:akeybl] 2012-03-22 13:46:29 PDT
Comment on attachment 607649 [details] [diff] [review]
patch

[Triage Comment]
Mobile only, approved for Aurora 13.
Comment 11 Mark Finkle (:mfinkle) (use needinfo?) 2012-03-24 07:52:23 PDT
https://hg.mozilla.org/releases/mozilla-aurora/rev/48b51740d3d2

Note You need to log in before you can comment on or make changes to this bug.