Fixed some sonar warnings

This commit is contained in:
litetex 2021-12-29 18:29:46 +01:00
parent 6b23df0659
commit 658168eb8d
1 changed files with 10 additions and 6 deletions

View File

@ -11,9 +11,12 @@ import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.util.PicassoHelper; import org.schabi.newpipe.util.PicassoHelper;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional; import java.util.Optional;
public class DebugSettingsFragment extends BasePreferenceFragment { public class DebugSettingsFragment extends BasePreferenceFragment {
private static final String DUMMY = "Dummy";
@Override @Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResourceRegistry(); addPreferencesFromResourceRegistry();
@ -61,18 +64,18 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
}); });
crashTheAppPreference.setOnPreferenceClickListener(preference -> { crashTheAppPreference.setOnPreferenceClickListener(preference -> {
throw new RuntimeException(); throw new RuntimeException(DUMMY);
}); });
showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> { showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this, ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this,
"Dummy", new RuntimeException("Dummy")); DUMMY, new RuntimeException(DUMMY));
return true; return true;
}); });
createErrorNotificationPreference.setOnPreferenceClickListener(preference -> { createErrorNotificationPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.createNotification(requireContext(), ErrorUtil.createNotification(requireContext(),
new ErrorInfo(new RuntimeException("Dummy"), UserAction.UI_ERROR, "Dummy")); new ErrorInfo(new RuntimeException(DUMMY), UserAction.UI_ERROR, DUMMY));
return true; return true;
}); });
} }
@ -81,9 +84,10 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
try { try {
// Try to find the implementation of the LeakCanary API // Try to find the implementation of the LeakCanary API
return Optional.of((DebugSettingsBVLeakCanaryAPI) return Optional.of((DebugSettingsBVLeakCanaryAPI)
Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS).newInstance()); Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS)
} catch (final ClassNotFoundException .getDeclaredConstructor()
| IllegalAccessException | java.lang.InstantiationException e) { .newInstance());
} catch (final Exception e) {
return Optional.empty(); return Optional.empty();
} }
} }