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

Fix ClassCastException caused by assuming editorFragment was a Gutenb… #21665

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Feb 6, 2025

Closes #21664

This PR fixes a ClassCastException caused by assuming editorFragment was a GutenbergEditorFragment when it could be a GutenbergKitEditorFragment in this code:

   @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(event: ConnectionChangeEvent) {
        if (editorFragment !is GutenbergNetworkConnectionListener) return
        (editorFragment as GutenbergEditorFragment).onConnectionStatusChange(event.isConnected)
    }

Since both of these fragments extend GutenbergNetworkConnectionListener we simply needed to change this to a safe cast for that listener.

@dcalhoun This crash started happening with 25.6, but given this is an experimental feature I wasn't sure if a hotfix was necessary.

To test:

  • Set a breakpoint here
  • Run the app in debug
  • Make sure the experimental editor is enabled
  • Edit a post
  • Turn on airplane mode
  • Note that breakpoint is reached and the app doesn't crash

…ergEditorFragment when it could be a GutenbergKitEditorFragment
@nbradbury nbradbury added [Type] Crash Gutenberg Editing and display of Gutenberg blocks. labels Feb 6, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 6, 2025

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

Copy link

sonarqubecloud bot commented Feb 6, 2025

@nbradbury nbradbury requested a review from dcalhoun February 6, 2025 18:56
@nbradbury nbradbury marked this pull request as ready for review February 6, 2025 18:57
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. These testing plan succeeded for me, the crash no longer occurs. Thank you for addressing this! 🙇🏻‍♂️

This crash started happening with 25.6, but given this is an experimental feature I wasn't sure if a hotfix was necessary.

Given the 25.6.1 release has not shipped, I suggest we include this in both the 25.6.1 and 25.7 releases. This crash could occur at any point if a user's network connection intermittently disconnects.

@wpmobilebot
Copy link
Contributor

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21665-8d33633
Commit8d33633
Direct Downloadwordpress-prototype-build-pr21665-8d33633.apk
Note: Google Login is not supported on these builds.

@nbradbury
Copy link
Contributor Author

Given the 25.6.1 release has not shipped, I suggest we include this in both the 25.6.1 and 25.7 releases.

👍 I'll work on PRs for both of these.

@wpmobilebot
Copy link
Contributor

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21665-8d33633
Commit8d33633
Direct Downloadjetpack-prototype-build-pr21665-8d33633.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.42%. Comparing base (369805d) to head (8d33633).
Report is 1 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #21665   +/-   ##
=======================================
  Coverage   39.42%   39.42%           
=======================================
  Files        2122     2122           
  Lines       99558    99558           
  Branches    15317    15317           
=======================================
  Hits        39247    39247           
  Misses      56832    56832           
  Partials     3479     3479           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nbradbury nbradbury merged commit f0971c4 into trunk Feb 6, 2025
27 checks passed
@nbradbury nbradbury deleted the issue/21664-gutenberg-class-cast-exception branch February 6, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks. [Type] Crash
Projects
None yet
4 participants