From 658168eb8d97e54ac23f1dfdccb7fd8ec2786035 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Wed, 29 Dec 2021 18:29:46 +0100 Subject: [PATCH] Fixed some sonar warnings --- .../newpipe/settings/DebugSettingsFragment.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 710a440e1..915531779 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -11,9 +11,12 @@ import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.util.PicassoHelper; +import java.lang.reflect.InvocationTargetException; import java.util.Optional; public class DebugSettingsFragment extends BasePreferenceFragment { + private static final String DUMMY = "Dummy"; + @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResourceRegistry(); @@ -61,18 +64,18 @@ public class DebugSettingsFragment extends BasePreferenceFragment { }); crashTheAppPreference.setOnPreferenceClickListener(preference -> { - throw new RuntimeException(); + throw new RuntimeException(DUMMY); }); showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> { ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this, - "Dummy", new RuntimeException("Dummy")); + DUMMY, new RuntimeException(DUMMY)); return true; }); createErrorNotificationPreference.setOnPreferenceClickListener(preference -> { ErrorUtil.createNotification(requireContext(), - new ErrorInfo(new RuntimeException("Dummy"), UserAction.UI_ERROR, "Dummy")); + new ErrorInfo(new RuntimeException(DUMMY), UserAction.UI_ERROR, DUMMY)); return true; }); } @@ -81,9 +84,10 @@ public class DebugSettingsFragment extends BasePreferenceFragment { try { // Try to find the implementation of the LeakCanary API return Optional.of((DebugSettingsBVLeakCanaryAPI) - Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS).newInstance()); - } catch (final ClassNotFoundException - | IllegalAccessException | java.lang.InstantiationException e) { + Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS) + .getDeclaredConstructor() + .newInstance()); + } catch (final Exception e) { return Optional.empty(); } }