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 NullPointerException by avoiding race condition #7689

Merged
merged 1 commit into from Mar 5, 2024

Conversation

cketti
Copy link
Member

@cketti cketti commented Mar 4, 2024

Fixes a crash reported via Google Play (K-9 Mail 6.800).

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.setProgress(int)' on a null object reference
  at com.fsck.k9.fragment.AttachmentDownloadDialogFragment$1.updateProgress (AttachmentDownloadDialogFragment.java:48)
  at com.fsck.k9.controller.MessagingController$4$1.updateProgress (MessagingController.java:1352)
  at com.fsck.k9.controller.ProgressBodyFactory$1.run (ProgressBodyFactory.java:29)
  at java.util.TimerThread.mainLoop (Timer.java:563)
  at java.util.TimerThread.run (Timer.java:513)

@cketti cketti requested a review from wmontwe as a code owner March 4, 2024 13:27
@cketti cketti changed the base branch from main to 6.8-MAINT March 4, 2024 14:41
Copy link
Collaborator

@wmontwe wmontwe left a comment

Choose a reason for hiding this comment

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

👍

I added a ticket to address the ProgressDialog deprecation warnings: #7696

@@ -42,6 +41,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

final SizeUnit sizeUnit = SizeUnit.getAppropriateFor(size);

ProgressDialog dialog = new ProgressDialog(getActivity());
Copy link
Collaborator

@wmontwe wmontwe Mar 5, 2024

Choose a reason for hiding this comment

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

We should use requireActivity(), it is not null and helps converting this class to Kotlin later. Also the generated error messages are more helpful for debugging.

Suggested change
ProgressDialog dialog = new ProgressDialog(getActivity());
ProgressDialog dialog = new ProgressDialog(requireActivity());

Copy link
Collaborator

@wmontwe wmontwe Mar 5, 2024

Choose a reason for hiding this comment

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

We could add a lint check to assist here. I'll create one when I have some spare time. #7695

@cketti cketti merged commit c9b74b1 into 6.8-MAINT Mar 5, 2024
2 checks passed
@cketti cketti deleted the avoid_crash_when_downloading_attachment branch March 5, 2024 12:10
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.

None yet

2 participants