diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfo.java b/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfo.java index 4ae289ec8..02d7bccbf 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfo.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfo.java @@ -7,7 +7,6 @@ import static java.util.Objects.requireNonNull; -import com.google.i18n.phonenumbers.PhoneNumberUtil; import javax.annotation.Nonnull; public record AsnInfo(long asn, @Nonnull String regionCode) { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImpl.java b/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImpl.java index e7713c83b..268baa2fe 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImpl.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImpl.java @@ -71,24 +71,24 @@ public static AsnInfoProviderImpl fromTsv(@Nonnull final InputStream tsvInputStr final Map asnInfoCache = new HashMap<>(); try (final CSVParser csvParser = CSVFormat.TDF.parse(tsvReader)) { - for (final CSVRecord record : csvParser) { + for (final CSVRecord csvRecord : csvParser) { // format: // range_start_ip_string range_end_ip_string AS_number country_code AS_description - final InetAddress startIp = InetAddress.getByName(record.get(0)); - final InetAddress endIp = InetAddress.getByName(record.get(1)); - final long asn = Long.parseLong(record.get(2)); - final String regionCode = record.get(3); + final InetAddress startIp = InetAddress.getByName(csvRecord.get(0)); + final InetAddress endIp = InetAddress.getByName(csvRecord.get(1)); + final long asn = Long.parseLong(csvRecord.get(2)); + final String regionCode = csvRecord.get(3); // country code should be the same for any ASN, so we're caching AsnInfo objects // not to have multiple instances with the same values - final AsnInfo asnInfo = asnInfoCache.computeIfAbsent(asn, k -> new AsnInfo(asn, regionCode)); + final AsnInfo asnInfo = asnInfoCache.computeIfAbsent(asn, _ -> new AsnInfo(asn, regionCode)); if (!regionCode.equals(asnInfo.regionCode())) { log.warn("ASN {} mapped to country codes {} and {}", asn, regionCode, asnInfo.regionCode()); } // IPv4 - if (startIp instanceof Inet4Address) { + if (startIp instanceof Inet4Address inet4address) { final AsnRange asnRange = new AsnRange<>( - ip4BytesToLong((Inet4Address) startIp), + ip4BytesToLong(inet4address), ip4BytesToLong((Inet4Address) endIp), asnInfo ); @@ -96,9 +96,9 @@ public static AsnInfoProviderImpl fromTsv(@Nonnull final InputStream tsvInputStr } // IPv6 - if (startIp instanceof Inet6Address) { + if (startIp instanceof Inet6Address inet6address) { final AsnRange asnRange = new AsnRange<>( - ip6BytesToBigInteger((Inet6Address) startIp), + ip6BytesToBigInteger(inet6address), ip6BytesToBigInteger((Inet6Address) endIp), asnInfo ); @@ -134,7 +134,7 @@ public Optional lookup(@Nonnull final String ipString) { } // safety net, should never happen log.warn("Unknown InetAddress implementation: {}", address.getClass().getName()); - } catch (final Exception e) { + } catch (final Exception _) { log.error("Could not resolve ASN for IP string {}", ipString); } return Optional.empty(); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImplTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImplTest.java index a16cdc07b..f07406883 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImplTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/asn/AsnInfoProviderImplTest.java @@ -19,7 +19,7 @@ import java.net.InetAddress; import org.junit.jupiter.api.Test; -public class AsnInfoProviderImplTest { +class AsnInfoProviderImplTest { private static final String RESOURCE_NAME = "ip2asn-test.tsv"; @@ -53,7 +53,7 @@ void testAsnInfo() throws IOException { } @Test - public void testBytesToLong() throws Exception { + void testBytesToLong() throws Exception { assertEquals(0x00000000ffffffffL, ip4BytesToLong((Inet4Address) InetAddress.getByName("255.255.255.255"))); assertEquals(0x0000000000000001L, ip4BytesToLong((Inet4Address) InetAddress.getByName("0.0.0.1"))); assertEquals(0x00000000ff00ff01L, ip4BytesToLong((Inet4Address) InetAddress.getByName("255.0.255.1")));