Skip to content

Commit

Permalink
Merge pull request #20470 from wordpress-mobile/fix/18652-plugin-error
Browse files Browse the repository at this point in the history
Handles NullPointerException in Plugin configuration
  • Loading branch information
mkevins authored Mar 15, 2024
2 parents 43338f0 + 9d21082 commit 9ded431
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,17 @@ protected void disableAndRemovePlugin() {

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSitePluginConfigured(OnSitePluginConfigured event) {
public void onSitePluginConfigured(@NonNull OnSitePluginConfigured event) {
if (isFinishing()) {
return;
}

if (event.site == null || event.pluginName == null) {
ToastUtils.showToast(this, getString(R.string.plugin_configuration_failed,
event.isError() ? event.error.message : getString(R.string.unknown)));
return;
}

if (!shouldHandleFluxCSitePluginEvent(event.site, event.pluginName)) {
return;
}
Expand Down Expand Up @@ -1061,11 +1067,17 @@ public void onWPOrgPluginFetched(OnWPOrgPluginFetched event) {

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSitePluginUpdated(OnSitePluginUpdated event) {
public void onSitePluginUpdated(@NonNull OnSitePluginUpdated event) {
if (isFinishing()) {
return;
}

if (event.site == null || event.pluginName == null) {
ToastUtils.showToast(this, getString(R.string.plugin_updated_failed,
event.isError() ? event.error.message : getString(R.string.unknown)));
return;
}

if (!shouldHandleFluxCSitePluginEvent(event.site, event.pluginName)) {
return;
}
Expand Down Expand Up @@ -1129,11 +1141,17 @@ public void onSitePluginInstalled(OnSitePluginInstalled event) {

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSitePluginDeleted(OnSitePluginDeleted event) {
public void onSitePluginDeleted(@NonNull OnSitePluginDeleted event) {
if (isFinishing()) {
return;
}

if (event.site == null || event.pluginName == null) {
ToastUtils.showToast(this, getString(R.string.plugin_remove_failed,
event.isError() ? event.error.message : getString(R.string.unknown)));
return;
}

if (!shouldHandleFluxCSitePluginEvent(event.site, event.pluginName)) {
return;
}
Expand Down Expand Up @@ -1165,8 +1183,8 @@ public void onSitePluginDeleted(OnSitePluginDeleted event) {

// This check should only handle events for already installed plugins - onSitePluginConfigured,
// onSitePluginUpdated, onSitePluginDeleted
private boolean shouldHandleFluxCSitePluginEvent(SiteModel eventSite, String eventPluginName) {
return mSite.getId() == eventSite.getId() // correct site
private boolean shouldHandleFluxCSitePluginEvent(@NonNull SiteModel eventSite, @NonNull String eventPluginName) {
return mSite != null && mSite.getId() == eventSite.getId() // correct site
&& mPlugin.isInstalled() // needs plugin to be already installed
&& mPlugin.getName() != null // sanity check for NPE since if plugin is installed it'll have the name
&& mPlugin.getName().equals(eventPluginName); // event is for the plugin we are showing
Expand Down

0 comments on commit 9ded431

Please sign in to comment.