1.55.0
Bugfix: Fix WebP ClassCastException
What happened
- Robolectric runs inside a custom class loader named
SdkSandboxClassLoader. - Roborazzi's WebP support relies on
ImageIO.getImageWritersByMIMEType, which internally caches writers in a static field. When the writer is first created, the code is executed by SdkSandboxClassLoader1. - Subsequently, when another test runs with a different SDK (e.g., 35), a second SdkSandboxClassLoader (SdkSandboxClassLoader2) is spawned. Because ImageIO's cached instance was loaded by a different class loader, attempting to cast it triggers a ClassCastException.
class com.luciad.imageio.webp.WebPWriteParam cannot be cast to class com.luciad.imageio.webp.WebPWriteParam (com.luciad.imageio.webp.WebPWriteParam is in unnamed module of loader org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader @1dbb650b; com.luciad.imageio.webp.WebPWriteParam is in unnamed module of loader org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader @3e48e859)
What we did
We leveraged reflection to force ImageIO.getImageWritersByMIMEType to use the System ClassLoader, thereby guaranteeing that the same class definition is shared irrespective of the current SdkSandboxClassLoader.
Many thanks to @eygraber for reporting this bug!
What's Changed
- Use File constructor for cross-platform path in IntelliJ plugin by @takahirom in https://github.com/takahirom/roborazzi/pull/775
- Fix WebP ClassCastException with multiple SDK configs by @takahirom in https://github.com/takahirom/roborazzi/pull/774
- Add reproduction test for issue #771 by @takahirom in https://github.com/takahirom/roborazzi/pull/773
Full Changelog: https://github.com/takahirom/roborazzi/compare/1.54.0...1.55.0