From 9c053e20daefd9492d18947c5a997d4aed5db53b Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Thu, 19 Oct 2023 19:11:53 -0400 Subject: [PATCH] Drop `Util#isEmpty`/`Util#nonEmpty` in favor of `StringUtils` --- .../auth/RegistrationLockVerificationManager.java | 4 ++-- .../textsecuregcm/auth/StoredRegistrationLock.java | 4 ++-- .../textsecuregcm/controllers/MessageController.java | 5 +++-- .../org/whispersystems/textsecuregcm/storage/Account.java | 4 ++-- .../org/whispersystems/textsecuregcm/storage/Device.java | 4 ++-- .../textsecuregcm/storage/PushFeedbackProcessor.java | 5 +++-- .../java/org/whispersystems/textsecuregcm/util/Util.java | 8 -------- 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManager.java index 0f80ca6d6..2629f69d9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManager.java @@ -18,6 +18,7 @@ import java.util.List; import javax.annotation.Nullable; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; +import org.apache.commons.lang3.StringUtils; import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException; import org.whispersystems.textsecuregcm.entities.PhoneVerificationRequest; import org.whispersystems.textsecuregcm.entities.RegistrationLockFailure; @@ -30,7 +31,6 @@ import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.storage.RegistrationRecoveryPasswordsManager; -import org.whispersystems.textsecuregcm.util.Util; public class RegistrationLockVerificationManager { public enum Flow { @@ -106,7 +106,7 @@ public class RegistrationLockVerificationManager { throw new RuntimeException("Unexpected status: " + existingRegistrationLock.getStatus()); } - if (!Util.isEmpty(clientRegistrationLock)) { + if (StringUtils.isNotEmpty(clientRegistrationLock)) { rateLimiters.getPinLimiter().validate(account.getNumber()); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/StoredRegistrationLock.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/StoredRegistrationLock.java index 276a4d6f7..905f141d9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/StoredRegistrationLock.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/StoredRegistrationLock.java @@ -11,7 +11,7 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Optional; import javax.annotation.Nullable; -import org.whispersystems.textsecuregcm.util.Util; +import org.apache.commons.lang3.StringUtils; @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class StoredRegistrationLock { @@ -73,7 +73,7 @@ public class StoredRegistrationLock { } public boolean verify(@Nullable String clientRegistrationLock) { - if (hasLockAndSalt() && Util.nonEmpty(clientRegistrationLock)) { + if (hasLockAndSalt() && StringUtils.isNotEmpty(clientRegistrationLock)) { SaltedTokenHash credentials = new SaltedTokenHash(registrationLock.get(), registrationLockSalt.get()); return credentials.verify(clientRegistrationLock); } else { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index 060c9c377..fdde522ef 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -61,6 +61,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.auth.Anonymous; @@ -226,7 +227,7 @@ public class MessageController { for (final IncomingMessage message : messages.messages()) { int contentLength = 0; - if (!Util.isEmpty(message.content())) { + if (StringUtils.isNotEmpty(message.content())) { contentLength += message.content().length(); } @@ -782,7 +783,7 @@ public class MessageController { } public static Optional getMessageContent(IncomingMessage message) { - if (Util.isEmpty(message.content())) return Optional.empty(); + if (StringUtils.isEmpty(message.content())) return Optional.empty(); try { return Optional.of(Base64.getDecoder().decode(message.content())); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index 0686307b1..1a518cc7d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -19,6 +19,7 @@ import java.util.Optional; import java.util.UUID; import java.util.function.Predicate; import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import org.signal.libsignal.protocol.IdentityKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +31,6 @@ import org.whispersystems.textsecuregcm.identity.ServiceIdentifier; import org.whispersystems.textsecuregcm.storage.Device.DeviceCapabilities; import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter; import org.whispersystems.textsecuregcm.util.IdentityKeyAdapter; -import org.whispersystems.textsecuregcm.util.Util; @JsonFilter("Account") public class Account { @@ -415,7 +415,7 @@ public class Account { } public void setRegistrationLockFromAttributes(final AccountAttributes attributes) { - if (!Util.isEmpty(attributes.getRegistrationLock())) { + if (StringUtils.isNotEmpty(attributes.getRegistrationLock())) { final SaltedTokenHash credentials = SaltedTokenHash.generateFor(attributes.getRegistrationLock()); setRegistrationLock(credentials.hash(), credentials.salt()); } else { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java index 06b61a719..37363d686 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java @@ -12,10 +12,10 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.LongStream; import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import org.whispersystems.textsecuregcm.auth.SaltedTokenHash; import org.whispersystems.textsecuregcm.entities.ECSignedPreKey; import org.whispersystems.textsecuregcm.identity.IdentityType; -import org.whispersystems.textsecuregcm.util.Util; public class Device { @@ -197,7 +197,7 @@ public class Device { } public boolean isEnabled() { - boolean hasChannel = fetchesMessages || !Util.isEmpty(getApnId()) || !Util.isEmpty(getGcmId()); + boolean hasChannel = fetchesMessages || StringUtils.isNotEmpty(getApnId()) || StringUtils.isNotEmpty(getGcmId()); return (id == PRIMARY_ID && hasChannel && signedPreKey != null) || (id != PRIMARY_ID && hasChannel && signedPreKey != null && lastSeen > (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30))); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/PushFeedbackProcessor.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PushFeedbackProcessor.java index 4e4173f08..ae1875143 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/PushFeedbackProcessor.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/PushFeedbackProcessor.java @@ -18,6 +18,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Metrics; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.metrics.MetricsUtil; @@ -81,13 +82,13 @@ public class PushFeedbackProcessor extends AccountDatabaseCrawlerListener { for (Device device : a.getDevices()) { if (deviceNeedsUpdate(device)) { if (deviceExpired(device)) { - if (!Util.isEmpty(device.getApnId())) { + if (StringUtils.isNotEmpty(device.getApnId())) { if (device.getId() == 1) { device.setUserAgent("OWI"); } else { device.setUserAgent("OWP"); } - } else if (!Util.isEmpty(device.getGcmId())) { + } else if (StringUtils.isNotEmpty(device.getGcmId())) { device.setUserAgent("OWA"); } device.setGcmId(null); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java index 4ddeedce5..6f9e8d912 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java @@ -96,14 +96,6 @@ public class Util { return number.substring(0, 1 + countryCode.length() + prefixLength); } - public static boolean isEmpty(String param) { - return param == null || param.length() == 0; - } - - public static boolean nonEmpty(String param) { - return !isEmpty(param); - } - public static byte[] truncate(byte[] element, int length) { byte[] result = new byte[length]; System.arraycopy(element, 0, result, 0, result.length);