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

int[] cannot be cast to java.lang.Object[] in setResourceDecoderBucketPriorityList #3296

Closed
zizikoth opened this issue Sep 4, 2018 · 10 comments
Labels

Comments

@zizikoth
Copy link

zizikoth commented Sep 4, 2018

Glide Version: 4.7.1

Integration libraries: com.squareup.okhttp3:okhttp:3.11.0

Device/Android Version: MeiZu M1 flymeos 4.2.1 (android4.4 API19)

Issue details / Repro steps / Use case background:

Glide load line / GlideModule (if any) / list Adapter code (if any):

GlideApp.with(context).load(path).into(imageView);

Layout XML:

Stack trace / LogCat:

java.lang.ClassCastException: int[] cannot be cast to java.lang.Object[]
        at java.util.Arrays$ArrayList.toArray(Arrays.java:120)
        at java.util.ArrayList.<init>(ArrayList.java:97)
        at com.bumptech.glide.Registry.setResourceDecoderBucketPriorityList(Registry.java:268)
        at com.bumptech.glide.Registry.<init>(Registry.java:67)
        at com.bumptech.glide.Glide.<init>(Glide.java:333)
        at com.bumptech.glide.GlideBuilder.build(GlideBuilder.java:452)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:264)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:219)
        at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:180)
        at com.bumptech.glide.Glide.get(Glide.java:164)
        at com.bumptech.glide.Glide.getRetriever(Glide.java:671)
        at com.bumptech.glide.Glide.with(Glide.java:698)
        at com.***.Glide.GlideApp.with(GlideApp.java:88)
        at com.***.GlideImageLoader.loadCircleImage(GlideImageLoader.java:58)
        at com.***.MineFragment.initView(MineFragment.java:116)
        at com.***.MineFragment.initialize(MineFragment.java:102)
        at com.***.Fragment.BaseFragment.onCreateView(BaseFragment.java:79)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2215)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
        at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
        at android.view.View.measure(View.java:17481)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
        at android.view.View.measure(View.java:17481)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5437)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
        at android.view.View.measure(View.java:17481)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:818)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:495)
        at android.view.View.measure(View.java:17481)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5437)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
        at android.view.View.measure(View.java:17481)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5437)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
        at android.view.View.measure(View.java:17481)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5437)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
        at android.view.View.measure(View.java:17481)
@zizikoth
Copy link
Author

zizikoth commented Sep 4, 2018

it's ok in Glide 4.1.1

@sjudd sjudd added the bug label Sep 4, 2018
@sjudd
Copy link
Collaborator

sjudd commented Sep 4, 2018

There's a note in the Android API 27 code for ArrayList that indicates that calling toArray() might erroneously return an array of an incorrect type:

   public ArrayList(Collection<? extends E> c) {
        elementData = c.toArray();
        if ((size = elementData.length) != 0) {
            // c.toArray might (incorrectly) not return Object[] (see 6260652)
            if (elementData.getClass() != Object[].class)
                elementData = Arrays.copyOf(elementData, size, Object[].class);
        } else {
            // replace with empty array.
            this.elementData = EMPTY_ELEMENTDATA;
        }
    }

@sjudd sjudd changed the title Crash on yunos android4.4 api19 Glide4.7.1 int[] cannot be cast to java.lang.Object[] in setResourceDecoderBucketPriorityList Sep 4, 2018
@sjudd sjudd closed this as completed in 2ca790a Sep 21, 2018
@hzyxym
Copy link

hzyxym commented Jan 9, 2019

And how to solve this bug?@sjudd

@wilsonssss
Copy link

MeiZu M1 crash too...

@EHG613
Copy link

EHG613 commented Apr 9, 2019

MeiZu M1 crash too... +1

@sjudd
Copy link
Collaborator

sjudd commented Apr 9, 2019

See the associated commit.

If you're able to reproduce this on 4.9.0+ let me know.

@EHG613
Copy link

EHG613 commented Apr 11, 2019

api 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
minSdkVersion 19
targetSdkVersion 27
compileSdkVersion 27

java.lang.ClassCastException: int[] cannot be cast to java.lang.Object[]
        at java.util.Arrays$ArrayList.toArray(Arrays.java:120)
        at java.util.ArrayList.addAll(ArrayList.java:188)
        at com.bumptech.glide.Registry.setResourceDecoderBucketPriorityList(Registry.java:270)
        at com.bumptech.glide.Registry.<init>(Registry.java:67)
        at com.bumptech.glide.Glide.<init>(Glide.java:339)
        at com.bumptech.glide.GlideBuilder.build(GlideBuilder.java:509)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:268)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:223)
        at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:184)
        at com.bumptech.glide.Glide.get(Glide.java:168)
        at com.bumptech.glide.Glide.getRetriever(Glide.java:689)
        at com.bumptech.glide.Glide.with(Glide.java:716)

@sjudd

@EHG613
Copy link

EHG613 commented Apr 12, 2019

setResourceDecoderBucketPriorityList(
        Arrays.asList(BUCKET_GIF, BUCKET_BITMAP, BUCKET_BITMAP_DRAWABLE));
public synchronized void setBucketPriorityList(@NonNull List<String> buckets) {
    List<String> previousBuckets = new ArrayList<>(bucketPriorityList);
    bucketPriorityList.clear();
    bucketPriorityList.addAll(buckets);
    for (String previousBucket : previousBuckets) {
      if (!buckets.contains(previousBucket)) {
        // Keep any buckets from the previous list that aren't included here, but but them at the
        // end.
        bucketPriorityList.add(previousBucket);
      }
    }
  }
  @NonNull
  public final Registry setResourceDecoderBucketPriorityList(@NonNull List<String> buckets) {
    // See #3296 and https://bugs.openjdk.java.net/browse/JDK-6260652.
    List<String> modifiedBuckets = new ArrayList<>(buckets.size());
    modifiedBuckets.addAll(buckets);
    modifiedBuckets.add(0, BUCKET_PREPEND_ALL);
    modifiedBuckets.add(BUCKET_APPEND_ALL);
    decoderRegistry.setBucketPriorityList(modifiedBuckets);
    return this;
  }

new ArrayList<>() maybe the crash reason @sjudd

@Logan676
Copy link

See the associated commit.

If you're able to reproduce this on 4.9.0+ let me know.

Using Glide 4.9.0, I have the same issue, with android
8.1.0, 9, 10.

devices show as below:

VKY-AL00 9.1.0.228(C00E80R1P12)
M1AJQ.C7100ZCU1BSA3
COL-TL10 10.0.0.156(C01E156R1P4)
HLK-AL00 10.1.0.110(C00E105R8P2)

crash log is

java.lang.ClassCastException: com.bumptech.glide.load.Option cannot be cast to java.lang.Object[]
 android.support.v4.util.SimpleArrayMap.allocArrays(SourceFile:15)
 android.support.v4.util.SimpleArrayMap.put(SourceFile:10)
 com.bumptech.glide.util.CachedHashCodeArrayMap.put(SourceFile:2)
 com.bumptech.glide.request.BaseRequestOptions.transform(SourceFile:23)
 com.bumptech.glide.request.BaseRequestOptions.transform(SourceFile:14)
 com.bumptech.glide.request.BaseRequestOptions.transform(SourceFile:5)
 m8.c.c0(SourceFile:1)
 m8.c.transform(SourceFile:1)
 com.bumptech.glide.request.BaseRequestOptions.transform(SourceFile:4)
 com.bumptech.glide.request.BaseRequestOptions.centerCrop(SourceFile:1)
 m8.c.c(SourceFile:1)
 m8.c.centerCrop(SourceFile:1)

Before, using Glide 3.5.2, didn`t have the issue.

@mohitrajput987
Copy link

mohitrajput987 commented May 26, 2021

We are also using
Glide 4.9.0

facing following issue in multiple devices and multiple OS:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{app.trell/com.example.MyActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2517)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
       at android.app.ActivityThread.access$1000(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5628)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
​
​
       Caused by java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]
       at android.util.ArrayMap.allocArrays(ArrayMap.java:173)
       at android.util.ArrayMap.put(ArrayMap.java:459)
       at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:736)
       at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1174)
       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1154)
       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1148)
       at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:554)
       at com.bumptech.glide.manager.DefaultConnectivityMonitor.register(DefaultConnectivityMonitor.java:55)
       at com.bumptech.glide.manager.DefaultConnectivityMonitor.onStart(DefaultConnectivityMonitor.java:101)
       at com.bumptech.glide.manager.ApplicationLifecycle.addListener(ApplicationLifecycle.java:15)
       at com.bumptech.glide.RequestManager.<init>(RequestManager.java:132)
       at com.bumptech.glide.RequestManager.<init>(RequestManager.java:94)
       at app.trell.network.GlideRequests.<init>(GlideRequests.java:39)
       at com.bumptech.glide.GeneratedRequestManagerFactory.build(GeneratedRequestManagerFactory.java:19)
       at com.bumptech.glide.manager.RequestManagerRetriever.getApplicationManager(RequestManagerRetriever.java:98)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:124)
       at com.bumptech.glide.Glide.with(Glide.java:716)
     
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2470)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
       at android.app.ActivityThread.access$1000(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5628)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants