Skip to content
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

StringIndexOutOfBoundsException when generating public keys under Traditional Chinese locale #493

Closed
yan12125 opened this issue Feb 27, 2017 · 1 comment

Comments

@yan12125
Copy link
Contributor

commented Feb 27, 2017

Steps to reprduce:

  1. Use Traditional Chinese locale. On my phone it's displayed as 中文(繁體)
  2. "Manage Pubkeys" (管理公鑰) => "+"
  3. Type a random name and hit "Generate" (產生)

Then the generation dialog crashes: (I add two Log.e() to see what's wrong)

02-28 02:29:35.812  27000    27000                  DEBUG  E  觸摸此方框來收集隨機數:0%完成
02-28 02:29:35.813  27000    27000                  DEBUG  E  -1
02-28 02:29:35.818  27000    27000         AndroidRuntime  D  Shutting down VM
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  FATAL EXCEPTION: main
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  Process: org.connectbot.debug, PID: 27000
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  java.lang.StringIndexOutOfBoundsException: length=16; regionStart=0; regionLength=-1
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at java.lang.String.startEndAndLength(String.java:298)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at java.lang.String.substring(String.java:1087)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at org.connectbot.util.EntropyView.onDraw(EntropyView.java:101)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:16200)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.updateDisplayListIfDirty(View.java:15197)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:15970)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.updateDisplayListIfDirty(View.java:15192)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:15970)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.updateDisplayListIfDirty(View.java:15192)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:15970)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.updateDisplayListIfDirty(View.java:15192)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:15970)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.draw(View.java:16203)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.View.updateDisplayListIfDirty(View.java:15197)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2620)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2439)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2072)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6035)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.Choreographer.doCallbacks(Choreographer.java:670)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.Choreographer.doFrame(Choreographer.java:606)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.os.Handler.handleCallback(Handler.java:739)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.os.Handler.dispatchMessage(Handler.java:95)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.os.Looper.loop(Looper.java:148)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at android.app.ActivityThread.main(ActivityThread.java:5451)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at java.lang.reflect.Method.invoke(Native Method)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-28 02:29:35.819  27000    27000         AndroidRuntime  E  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Everything works fine with English locale.

Tested with the latest git master (0a380c1)

@kruton kruton added the bug label Feb 27, 2017

@yan12125

This comment has been minimized.

Copy link
Contributor Author

commented Mar 1, 2017

OK I got a workaround for that:

diff --git a/app/src/main/java/org/connectbot/util/EntropyView.java b/app/src/main/java/org/connectbot/util/EntropyView.java
index e25cb0d..c7411b0 100644
--- a/app/src/main/java/org/connectbot/util/EntropyView.java
+++ b/app/src/main/java/org/connectbot/util/EntropyView.java
@@ -94,6 +94,8 @@ public class EntropyView extends View {
                mPaint.measureText(prompt) > (getWidth() * 0.8)) {
            if (splitText == 0)
                splitText = prompt.indexOf(' ', prompt.length() / 2);
+           if (splitText < 0)
+               splitText = prompt.length() / 2;
 
            c.drawText(prompt.substring(0, splitText),
                    getWidth() / 2.0f,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.