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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,7 +18,6 @@ public class AttachmentDownloadDialogFragment extends DialogFragment {
private static final String ARG_MESSAGE = "message";


private ProgressDialog dialog;
private MessagingListener messagingListener;
private MessagingController messagingController;

Expand All @@ -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

dialog.setMessage(message);
dialog.setMax(sizeUnit.valueInSizeUnit(size));
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.setProgressNumberFormat("%1d/%2d " + sizeUnit.shortName);
dialog.show();

messagingListener = new SimpleMessagingListener() {
@Override
public void updateProgress(int progress) {
Expand All @@ -52,14 +59,6 @@ public void updateProgress(int progress) {
messagingController = MessagingController.getInstance(getActivity());
messagingController.addListener(messagingListener);

dialog = new ProgressDialog(getActivity());
dialog.setMessage(message);
dialog.setMax(sizeUnit.valueInSizeUnit(size));
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.setProgressNumberFormat("%1d/%2d " + sizeUnit.shortName);
dialog.show();

return dialog;
}

Expand Down