Browse Source

Merge pull request #12832 from Pixee-Bot-Java/pixeebot/drip-2024-03-26-pixee-java/switch-literal-first

Switch order of literals to prevent NullPointerException
Tobias Kaminsky 7 months ago
parent
commit
cbc5fe4ef7

+ 2 - 2
app/src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -183,7 +183,7 @@ public abstract class AbstractIT {
         String darkModeParameter = arguments.getString("DARKMODE");
 
         if (darkModeParameter != null) {
-            if (darkModeParameter.equalsIgnoreCase("dark")) {
+            if ("dark".equalsIgnoreCase(darkModeParameter)) {
                 DARK_MODE = "dark";
                 AppPreferencesImpl.fromContext(targetContext).setDarkThemeMode(DarkMode.DARK);
                 MainApp.setAppTheme(DarkMode.DARK);
@@ -192,7 +192,7 @@ public abstract class AbstractIT {
             }
         }
 
-        if (DARK_MODE.equalsIgnoreCase("light") && COLOR.equalsIgnoreCase("blue")) {
+        if ("light".equalsIgnoreCase(DARK_MODE) && "blue".equalsIgnoreCase(COLOR)) {
             // use already existing names
             DARK_MODE = "";
             COLOR = "";

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/UploadIT.java

@@ -515,7 +515,7 @@ public class UploadIT extends AbstractOnServerIT {
 
         OCFile ocFile = null;
         for (OCFile f : files) {
-            if (f.getFileName().equals("metadata.jpg")) {
+            if ("metadata.jpg".equals(f.getFileName())) {
                 ocFile = f;
                 break;
             }

+ 1 - 1
app/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java

@@ -124,7 +124,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
             try {
                 String publicKey = EncryptionUtils.getPublicKey(user, shareeName, arbitraryDataProvider);
 
-                if (publicKey.equals("")) {
+                if ("".equals(publicKey)) {
                     NextcloudClient nextcloudClient = new ClientFactoryImpl(context).createNextcloudClient(user);
                     RemoteOperationResult<String> result = new GetPublicKeyRemoteOperation(shareeName).execute(nextcloudClient);
                     if (result.isSuccess()) {

+ 2 - 2
app/src/main/java/third_parties/sufficientlysecure/CalendarSource.java

@@ -50,13 +50,13 @@ public class CalendarSource {
             String protocol = mUrl.getProtocol();
             String userPass = mUsername + ":" + mPassword;
 
-            if (protocol.equalsIgnoreCase("ftp") || protocol.equalsIgnoreCase("ftps")) {
+            if ("ftp".equalsIgnoreCase(protocol) || "ftps".equalsIgnoreCase(protocol)) {
                 String external = mUrl.toExternalForm();
                 String end = external.substring(protocol.length() + HTTP_SEP.length());
                 return new URL(protocol + HTTP_SEP + userPass + "@" + end).openConnection();
             }
 
-            if (protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("https")) {
+            if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
                 String encoded = new String(new Base64().encode(userPass.getBytes("UTF-8")));
                 URLConnection connection = mUrl.openConnection();
                 connection.setRequestProperty("Authorization", "Basic " + encoded);

+ 1 - 1
app/src/main/java/third_parties/sufficientlysecure/ProcessVEvent.java

@@ -567,7 +567,7 @@ public class ProcessVEvent {
         String expected = parts.length > 1 ? parts[1] : "";
         String got = c.getAsString(key);
 
-        if (expected.equals("<non-null>") && got != null) {
+        if ("<non-null>".equals(expected) && got != null) {
             got = "<non-null>"; // Sentinel for testing present and non-null
         }
         if (got == null) {

+ 1 - 1
app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java

@@ -478,7 +478,7 @@ public class SaveCalendar {
             return true;
         }
         final String utz = tz.toUpperCase(Locale.US);
-        return utz.equals("UTC") || utz.equals("UTC-0") || utz.equals("UTC+0") || utz.endsWith("/UTC");
+        return "UTC".equals(utz) || "UTC-0".equals(utz) || "UTC+0".equals(utz) || utz.endsWith("/UTC");
     }
 
     private Date getDateTime(Cursor cur, String dbName, String dbTzName, Calendar cal) {