Skip to content

Conversation

graycreate
Copy link
Member

Summary

  • Adds comprehensive null checks in HtmlMovementMethod.onSpanClick() method
  • Prevents NullPointerException when clicking on image spans
  • Ensures safe comparison of image URLs

Problem

The app was crashing with the following stack trace from Google Play Console:

java.lang.NullPointerException:
  at me.ghui.v2er.widget.richtext.HtmlMovementMethod.onSpanClick (HtmlMovementMethod.java:215)
  at me.ghui.v2er.widget.richtext.HtmlMovementMethod.onTouchEvent (HtmlMovementMethod.java:257)

Root Cause

At line 215, the code was comparing currentImg.equals(imgs.get(i).getUrl()) without checking if:

  1. imgs collection is null
  2. currentImg is null
  3. imgs.get(i) is null
  4. imgs.get(i).getUrl() returns null

Any of these being null would cause a NullPointerException.

Solution

Added defensive null checks:

  • Check if imgs and currentImg are not null before iterating
  • Safely extract URL from image object with null check
  • Use proper null-safe comparison

Test Plan

  • Build project successfully
  • Verify image click handling works when imgs is properly initialized
  • Monitor crash reports after release to confirm fix

🤖 Generated with Claude Code

- Add null check for imgs collection before iterating
- Add null check for currentImg before comparison
- Add null check for imgs.get(i) and its getUrl() method
- Prevents NullPointerException when clicking on image spans
- Fixes crash reported in Google Play Console at line 215

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 10:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical NullPointerException crash in the HtmlMovementMethod's image click handling by adding comprehensive null safety checks. The crash was occurring when users clicked on image spans in the rich text widget.

  • Adds null checks for the imgs collection and currentImg string before processing
  • Implements safe URL extraction from image objects with null validation
  • Wraps the image iteration logic in a null safety guard

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +217 to +218
String imgUrl = imgs.get(i) != null ? imgs.get(i).getUrl() : null;
if (currentImg.equals(imgUrl)) {
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

This code will still throw a NullPointerException if imgUrl is null. The equals method should be called on the potentially null variable or use Objects.equals() for null-safe comparison. Consider changing to Objects.equals(currentImg, imgUrl) or imgUrl != null && imgUrl.equals(currentImg).

Copilot uses AI. Check for mistakes.

@graycreate graycreate merged commit 7064aa0 into main Sep 17, 2025
5 checks passed
@graycreate graycreate deleted the bugfix/html-movement-method-npe branch September 17, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant