From bdafe2ca8f95fc8702d07008838140f09191bf1d Mon Sep 17 00:00:00 2001 From: Hugh Daschbach Date: Thu, 23 Mar 2023 23:22:27 -0700 Subject: [PATCH] Fix ColorResourcesTableCreator creation exception. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A java.lang.ArrayIndexOutOfBoundsException is thrown the third, and subsequent times, ThemeHelper.applyCustomColors() is called. ,---- | java.lang.ArrayIndexOutOfBoundsException: src.length=128 srcPos=0 dst.length=131 dstPos=2 length=-128 `---- One way to trigger this is to call ConversationsOverviewFragment.onStart() three times. For example, open the app then, three dot menu -> Settings, back, three dot menu -> Settings, back. The exception is raised at line ColorResourcesTableCreator.java:616. So, stringToByteArrayUtf8() is ill prepared to deal with a string longer than 127 bytes. While the cast to signed byte is the immediate cause of the exception, the root cause is growth of the ColorResource name string as the package name is prepended to the color resource name on each pass through ColorResourceTableCreator.create(). Using Resource.getResourceEntryName() instead of Resource.getResourceName() prevents this. For the record, here’s the Exception stack trace: 2023-03-23 23:18:34.592 622-622 ColorResou...derCreator com.cheogram.android E Failed to create the ColorResourcesTableCreator. java.lang.ArrayIndexOutOfBoundsException: src.length=128 srcPos=0 dst.length=131 dstPos=2 length=-128 at java.lang.System.arraycopy(Native Method) at com.cheogram.android.ColorResourcesTableCreator.stringToByteArrayUtf8(ColorResourcesTableCreator.java:616) at com.cheogram.android.ColorResourcesTableCreator.access$800(ColorResourcesTableCreator.java:40) at com.cheogram.android.ColorResourcesTableCreator$StringPoolChunk.processString(ColorResourcesTableCreator.java:299) at com.cheogram.android.ColorResourcesTableCreator$StringPoolChunk.(ColorResourcesTableCreator.java:223) at com.cheogram.android.ColorResourcesTableCreator$PackageChunk.(ColorResourcesTableCreator.java:347) at com.cheogram.android.ColorResourcesTableCreator$ResTable.(ColorResourcesTableCreator.java:140) at com.cheogram.android.ColorResourcesTableCreator.create(ColorResourcesTableCreator.java:114) at com.cheogram.android.ColorResourcesLoaderCreator.create(ColorResourcesLoaderCreator.java:45) at eu.siacs.conversations.utils.ThemeHelper.applyCustomColors(ThemeHelper.java:67) at eu.siacs.conversations.ui.ConversationsActivity.onStart(ConversationsActivity.java:658) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455) at android.app.Activity.performStart(Activity.java:8076) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3660) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) --- .../java/com/cheogram/android/ColorResourcesTableCreator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cheogram/java/com/cheogram/android/ColorResourcesTableCreator.java b/src/cheogram/java/com/cheogram/android/ColorResourcesTableCreator.java index 1a0620e4687be30c0936c8cb5f55dfa2389e2a29..59807aa6a2484c25a5d586fe033d83e4d2586169 100644 --- a/src/cheogram/java/com/cheogram/android/ColorResourcesTableCreator.java +++ b/src/cheogram/java/com/cheogram/android/ColorResourcesTableCreator.java @@ -77,7 +77,7 @@ final class ColorResourcesTableCreator { colorResource = new ColorResource( entry.getKey(), - context.getResources().getResourceName(entry.getKey()), + context.getResources().getResourceEntryName(entry.getKey()), entry.getValue()); if (!context .getResources()