Skip to content

Conversation

@graycreate
Copy link
Member

Summary

  • Fixes crash that occurs when clicking on images with null data in reply lists
  • Only affected release builds due to ProGuard obfuscation issues
  • Adds validation and null safety checks to prevent crashes

Problem

The app crashed with a NullPointerException when users clicked on images in reply lists that had null or invalid image data. This only occurred in release builds because ProGuard was obfuscating the ImagesInfo classes, breaking the Fruit HTML parsing library's reflection mechanism.

Solution

  1. Added validation in GalleryActivity.open(): Checks if images are valid before opening gallery
  2. Added null safety checks in GalleryAdapter: Handles null image objects gracefully
  3. Added ProGuard rules: Prevents ImagesInfo classes from being obfuscated
  4. Shows user-friendly message: Displays "图片不存在" toast instead of crashing

Testing

  • Tested with debug build - no crash
  • Tested with release build - no crash
  • Clicking valid images opens gallery normally
  • Clicking invalid/null images shows toast message

Related Issues

Fixes crash reported when clicking images in reply lists

🤖 Generated with Claude Code

- Add validation in GalleryActivity.open() to check for null/invalid images before opening gallery
- Add null safety checks in GalleryAdapter to handle null image objects
- Add null checks in getCurrentImage() and menu actions to prevent NPE
- Add ProGuard rules to keep ImagesInfo classes from being obfuscated
- Show "图片不存在" toast when attempting to open gallery with invalid images

This fixes the crash that occurred only in release builds when clicking
on images in reply lists that had null or invalid image data.

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

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

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 crash that occurs when clicking on images with null or invalid data in reply lists, specifically affecting release builds due to ProGuard obfuscation issues with the Fruit HTML parsing library.

  • Adds comprehensive null safety validation before opening the gallery
  • Implements defensive programming in gallery adapter and activity methods
  • Adds ProGuard rules to prevent obfuscation of ImagesInfo classes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
GalleryActivity.java Adds validation in open() method and null checks in image handling methods
GalleryAdapter.java Adds bounds checking and null safety in getItem() and instantiateItem() methods
proguard-rules.pro Adds keep rules for ImagesInfo classes to prevent obfuscation

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

Comment on lines 51 to 56
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
Copy link

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.

Parameter name has a typo: 'postion' should be 'position'.

Suggested change
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
private ImagesInfo.Images.Image getItem(int position) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
position < 0 || position >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(position);

Copilot uses AI. Check for mistakes.
Comment on lines 51 to 56
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
Copy link

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.

Variable name has a typo: 'postion' should be 'position' (appears twice in this condition).

Suggested change
private ImagesInfo.Images.Image getItem(int postion) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
postion < 0 || postion >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(postion);
private ImagesInfo.Images.Image getItem(int position) {
if (mImagesInfo == null || mImagesInfo.getImages() == null ||
position < 0 || position >= mImagesInfo.getImages().size()) {
return null;
}
return mImagesInfo.getImages().get(position);

Copilot uses AI. Check for mistakes.
@graycreate graycreate merged commit 5a6ce43 into main Sep 17, 2025
5 checks passed
@graycreate graycreate deleted the bugfix/gallery-crash-fix branch September 17, 2025 11:42
graycreate added a commit that referenced this pull request Sep 17, 2025
- Version code: 237
- Includes gallery crash fix from PR #110
graycreate added a commit that referenced this pull request Sep 17, 2025
- Version code: 237
- Includes gallery crash fix from PR #110
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.

2 participants