phikal / ReGeX

A Regular Expression game for Android
https://f-droid.org/en/packages/com.phikal.regex/
GNU General Public License v3.0
101 stars 10 forks source link

IndexOutOfBoundsException when opening the application #31

Closed Lonami closed 7 years ago

Lonami commented 7 years ago

Stack trace:

(Edit: Relevant part of the stack trace is at com.phikal.regex.Activities.GameActivity.onResume(GameActivity.java:228), full stack trace below).

Process: com.phikal.regex, PID: 28492
java.lang.RuntimeException: Unable to resume activity {com.phikal.regex/com.phikal.regex.Activities.GameActivity}: java.lang.IndexOutOfBoundsException: setSpan (16 ... 16) ends beyond length 0
  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3000)
  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3031)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2409)
  at android.app.ActivityThread.access$800(ActivityThread.java:145)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5319)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IndexOutOfBoundsException: setSpan (16 ... 16) ends beyond length 0
  at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1018)
  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:607)
  at android.text.Selection.setSelection(Selection.java:76)
  at android.widget.EditText.setSelection(EditText.java:92)
  at com.phikal.regex.Activities.GameActivity.onResume(GameActivity.java:228)
  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1241)
  at android.app.Activity.performResume(Activity.java:6062)
  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2989)
  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3031) 
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2409) 
  at android.app.ActivityThread.access$800(ActivityThread.java:145) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:135) 
  at android.app.ActivityThread.main(ActivityThread.java:5319) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at java.lang.reflect.Method.invoke(Method.java:372) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Steps to reproduce

  1. Use the code up to #8009ec commit.
  2. Accomplish some task.
  3. Leave the game and clear it from recent apps.
  4. Try to play again.

Note that this also happened when I updated from the old version to this one. I can't remember if it happened on the previous version, but I think it didn't.

phikal commented 7 years ago

What game mode were you using?

Lonami commented 7 years ago

REDB server game mode, connected to the internet.

phikal commented 7 years ago

I'm sorry, but I can't reproduce it. What device/language are you using?

Lonami commented 7 years ago

I'm using a Sony Xperia M4 Aqua set to English (United Kingdom) under Settings/Language & Input.

Edit: I've tried changing it to Spanish (Spain). Same result (I didn't uninstall or clear application data, it is as it was when this first happened).

phikal commented 7 years ago

I'm not sure about the device, but since I use United Kingdom English too, that shouldn't be the problem.

Do you have root access? And if so, could you post the preferences file (/data/data/com.phikal.regex/shared_prefs/com.phikal.regex_preferences.xml), since line 228, sets what part of the EditText box should be selected. IndexOutOfBoundsException would make be believe, that this selection wasn't saved properly, and therefore provoking the exception.

Edit: Nevermind, I managed to reproduce the bug myself. You just have to select some text, and then leave the app. I'll try and fix it before F-Droid builds the app - thanks for noticing

Lonami commented 7 years ago

Got root?

Never have enough ;) The file looks something like this:

<map>
    <string name="cache_matchmode-redb"> x1Fftp://ftp.is.co.za/rfc/rfc1808.txt x1F x1E x1Fhttp://www.ietf.org/rfc/rfc2396.txt x1F x1E x1Fldap://[2001:db8::7]/c=GB?objectClass?one x1F x1E x1Fmailto:John.Doe@example.com x1F x1E x1Fnews:comp.infosystems.www.servers.unix x1F x1E x1Ftel:+1-816-555-1212 x1F x1E x1Ftelnet://192.0.2.16:80/ x1F x x1D x1Fftp.is.co.za/rfc/rfc1808.txt x1F x1E x1Fhttp:/www.ietf.org/rfc/rfc2396.txt x1F x1E x1Fldap://2001:db8::7/c=GB?objectClass?one x1F x1E x1Fmailto://John.Doe@example.com x1F x1E x1Fnews://comp.infosystems.www.servers.unix/ x1F x1E x1Ftel:18165551212 x1F x1E x1Ftelnet:://192.0.2.16:80/ x1F x</string>
    <int name="position_e_matchmode-random" value="0" />
    <int name="position_s_matchmode-random" value="0" />
    <int name="position_s_matchmode-redb" value="16" />
    <int name="score_matchmode-redb" value="60" />
    <boolean name="regen" value="false" />
    <string name="gamemode">matchmode-redb</string>
    <int name="game_matchmode-redb" value="1" />
    <string name="input_matchmode-redb">\w+:(//)?[\w./]+</string>
    <int name="position_e_matchmode-redb" value="16" />
    <string name="input_matchmode-random"></string>
    <string name="vers">1.3</string>
    <string name="cache_matchmode-random"> x1Fa9 x1F x1D x1F0 x1F</string>
    <int name="diff_matchmode-redb" value="6" />
</map>

Edit: Oh alright, smart notice! Thank you for fixing it.

Lonami commented 7 years ago

Jeez, that's #efficiency, well done 😁