Skip to content

fix: get image info before creating drawable to avoid IllegalStateException#2839

Closed
kagod-dev wants to merge 1 commit into
facebook:mainfrom
kagod-dev:get-imageinfo-before-creating-drawable
Closed

fix: get image info before creating drawable to avoid IllegalStateException#2839
kagod-dev wants to merge 1 commit into
facebook:mainfrom
kagod-dev:get-imageinfo-before-creating-drawable

Conversation

@kagod-dev

@kagod-dev kagod-dev commented Sep 29, 2025

Copy link
Copy Markdown

Motivation

This PR aims to mitigate crash caused by IllegalStateException thrown due to closable image reference being already closed when getting the image info.
The crash is reported as #2826. On my end with version 3.6.0 I get following stack trace

java.lang.IllegalStateException: null
    at com.facebook.common.internal.Preconditions.checkState(Preconditions.java:162)
    at com.facebook.drawee.backends.pipeline.PipelineDraweeController.getImageInfo(PipelineDraweeController.java:366)
    at com.facebook.drawee.backends.pipeline.PipelineDraweeController.getImageInfo(PipelineDraweeController.java:64)
    at com.facebook.drawee.controller.AbstractDraweeController.reportSuccess(AbstractDraweeController.java:849)
    at com.facebook.drawee.controller.AbstractDraweeController.onNewResultInternal(AbstractDraweeController.java:667)
    at com.facebook.drawee.controller.AbstractDraweeController.-$$Nest$monNewResultInternal
    at com.facebook.drawee.controller.AbstractDraweeController$2.onNewResultImpl(AbstractDraweeController.java:600)
    at com.facebook.datasource.BaseDataSubscriber.onNewResult(BaseDataSubscriber.java:51)
    at com.facebook.datasource.AbstractDataSource$1.run(AbstractDataSource.java:200)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:257)
    at android.os.Looper.loop(Looper.java:342)
    at android.app.ActivityThread.main(ActivityThread.java:9634)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:619)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)

To mitigate the crash I moved reading image info before creating drawable from it and to be also surrounded by try-catch.

Test Plan

Unfortunately I can't provide a test plan since the exception is thrown most likely due to some race condition.

@meta-cla meta-cla Bot added the CLA Signed label Sep 29, 2025
@androideveloper

Copy link
Copy Markdown

Hey @oprisnik 👋 Thanks for maintaining Fresco!
We opened this PR a little while ago and wanted to follow up to see if there’s anything we can do to help move it forward! Really appreciate your time!

@meta-codesync

meta-codesync Bot commented Nov 20, 2025

Copy link
Copy Markdown

@oprisnik has imported this pull request. If you are a Meta employee, you can view this in D87565917.

@oprisnik

Copy link
Copy Markdown
Contributor

Thanks for the PR, we'll take a look.

@meta-codesync

meta-codesync Bot commented Dec 1, 2025

Copy link
Copy Markdown

@oprisnik merged this pull request in 64f3ca9.

@androideveloper

Copy link
Copy Markdown

thanks! do you know when is the next release planned? @oprisnik

@dodeja27

dodeja27 commented Feb 11, 2026

Copy link
Copy Markdown

Hi team,

We’re hitting a significant volume of production crashes caused by
Preconditions.checkState and this PR seems to directly address the root cause.

image

Since this is affecting a large number of users, could you please clarify:

  • Is there a release planned that includes this fix?
  • Or should consumers rely on a workaround / custom patch for now?
@1wayticket

Copy link
Copy Markdown

Hi team,

We’re hitting a significant volume of production crashes caused by
Preconditions.checkState and this PR seems to directly address the root cause.

image

Since this is affecting a large number of users, could you please clarify:

  • Is there a release planned that includes this fix?
  • Or should consumers rely on a workaround / custom patch for now?

We have sloved this problem by remove imageloading from non-main thread。
fresco will load from main thread automatically when lifecycle changed, there will be thread conflict if you load from non-main thread in your code.maybe you can self-check first. I hope it can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment