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.<init>(ColorResourcesTableCreator.java:223)
at com.cheogram.android.ColorResourcesTableCreator$PackageChunk.<init>(ColorResourcesTableCreator.java:347)
at com.cheogram.android.ColorResourcesTableCreator$ResTable.<init>(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)
After merging 39a2d3e, "Failed to inflate ColorStateList" warnings
overwhelm logcat output. This may be Android version specific. But
on an API 30 avd, this makes it difficult to spot other errors while
debugging. Full traceback below.
https://stackoverflow.com/questions/71746801/getting-failed-to-inflate-colorstatelist-leaving-it-to-the-framework-when-usi
suggests a fix, applied here.
Traceback (slightly reformatted):
```
2023-03-14 15:02:00.951 6324-6324 ResourcesCompat com.cheogram.android W Failed to inflate ColorStateList, leaving it to the framework
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0400eb a=-1}
at android.content.res.TypedArray.getColor(TypedArray.java:528)
at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:262)
at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:236)
at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:519)
at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:65)
at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:114)
at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:92)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at eu.siacs.conversations.ui.adapter.ConversationAdapter.onCreateViewHolder(ConversationAdapter.java:50)
at eu.siacs.conversations.ui.adapter.ConversationAdapter.onCreateViewHolder(ConversationAdapter.java:34)
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1213)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:899)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:919)
at android.view.View.layout(View.java:22844)
W at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:784)
at android.view.View.layout(View.java:22844)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3475)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2943)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1948)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8177)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
```
Hugh Daschbach
created
cdec63d
Do not include fallback quote on direct reply
Click to expand commit body
It may be too close to the preceeding message and confusing looking on clients
that use the fallback.