diff --git a/README.md b/README.md index e79537b5..0c835316 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ next (snapshot) release, e.g. `1.1-SNAPSHOT` after releasing `1.0`. ## Changelog +## 2024-xx-yy 1.40 + * Clean up some style (SonarQube) warnings + ## 2024-04-08 1.39.1 * Fix: Javadoc syntax error that broke the previous release tag * Javadoc now runs on ever `verify` build. diff --git a/src/main/java/net/ripe/rpki/commons/crypto/x509cert/X509ResourceCertificateBuilder.java b/src/main/java/net/ripe/rpki/commons/crypto/x509cert/X509ResourceCertificateBuilder.java index c1967ef5..845ab0e0 100644 --- a/src/main/java/net/ripe/rpki/commons/crypto/x509cert/X509ResourceCertificateBuilder.java +++ b/src/main/java/net/ripe/rpki/commons/crypto/x509cert/X509ResourceCertificateBuilder.java @@ -4,7 +4,6 @@ import net.ripe.ipresource.IpResourceType; import net.ripe.rpki.commons.crypto.ValidityPeriod; import org.apache.commons.lang3.Validate; -import org.bouncycastle.asn1.x509.PolicyInformation; import javax.security.auth.x500.X500Principal; import java.math.BigInteger; @@ -29,7 +28,7 @@ public X509ResourceCertificateBuilder() { builderHelper = new X509CertificateBuilderHelper(); builderHelper.withResources(resources); // https://tools.ietf.org/html/rfc6487#section-4.8.9 - builderHelper.withPolicies(X509ResourceCertificate.POLICY_INFORMATION); + builderHelper.withPolicies(AbstractX509CertificateWrapper.POLICY_INFORMATION); } public X509ResourceCertificateBuilder withSignatureProvider(String signatureProvider) { @@ -111,6 +110,7 @@ public X509ResourceCertificate build() { return new X509ResourceCertificate(builderHelper.generateCertificate()); } + @SuppressWarnings("java:S1319") public X509ResourceCertificateBuilder withInheritedResourceTypes(EnumSet resourceTypes) { this.inheritedResourceTypes = resourceTypes; builderHelper.withInheritedResourceTypes(resourceTypes); diff --git a/src/main/java/net/ripe/rpki/commons/provisioning/payload/list/response/ResourceClassListResponsePayloadSerializer.java b/src/main/java/net/ripe/rpki/commons/provisioning/payload/list/response/ResourceClassListResponsePayloadSerializer.java index 1e4455bb..98a5fda5 100644 --- a/src/main/java/net/ripe/rpki/commons/provisioning/payload/list/response/ResourceClassListResponsePayloadSerializer.java +++ b/src/main/java/net/ripe/rpki/commons/provisioning/payload/list/response/ResourceClassListResponsePayloadSerializer.java @@ -6,7 +6,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningCmsCertificateParser.java b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningCmsCertificateParser.java index 1629b5a0..bb2b9457 100644 --- a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningCmsCertificateParser.java +++ b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningCmsCertificateParser.java @@ -2,8 +2,6 @@ import net.ripe.rpki.commons.crypto.x509cert.X509CertificateParser; -import java.security.cert.X509Certificate; - import static net.ripe.rpki.commons.validation.ValidationString.*; public class ProvisioningCmsCertificateParser extends X509CertificateParser { diff --git a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateBuilder.java b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateBuilder.java index f4f17b1b..ea99db27 100644 --- a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateBuilder.java +++ b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateBuilder.java @@ -1,11 +1,9 @@ package net.ripe.rpki.commons.provisioning.x509; import com.google.common.base.Preconditions; -import com.google.common.base.Verify; import net.ripe.rpki.commons.crypto.ValidityPeriod; import net.ripe.rpki.commons.crypto.x509cert.X509CertificateBuilderHelper; import net.ripe.rpki.commons.util.UTC; -import org.apache.commons.lang3.Validate; import org.bouncycastle.asn1.x509.KeyUsage; import org.joda.time.DateTime; diff --git a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateParser.java b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateParser.java index d8e14dc3..1d77634b 100644 --- a/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateParser.java +++ b/src/main/java/net/ripe/rpki/commons/provisioning/x509/ProvisioningIdentityCertificateParser.java @@ -2,8 +2,6 @@ import net.ripe.rpki.commons.crypto.x509cert.X509CertificateParser; -import java.security.cert.X509Certificate; - import static net.ripe.rpki.commons.validation.ValidationString.*; public class ProvisioningIdentityCertificateParser extends X509CertificateParser { diff --git a/src/main/java/net/ripe/rpki/commons/validation/ValidationLocation.java b/src/main/java/net/ripe/rpki/commons/validation/ValidationLocation.java index ab0e19c7..bda07388 100644 --- a/src/main/java/net/ripe/rpki/commons/validation/ValidationLocation.java +++ b/src/main/java/net/ripe/rpki/commons/validation/ValidationLocation.java @@ -48,11 +48,7 @@ public boolean equals(Object o) { ValidationLocation that = (ValidationLocation) o; - if (!name.equals(that.name)) { - return false; - } - - return true; + return name.equals(that.name); } @Override diff --git a/src/main/java/net/ripe/rpki/commons/validation/ValidationMetric.java b/src/main/java/net/ripe/rpki/commons/validation/ValidationMetric.java index 32287bba..ff0522df 100644 --- a/src/main/java/net/ripe/rpki/commons/validation/ValidationMetric.java +++ b/src/main/java/net/ripe/rpki/commons/validation/ValidationMetric.java @@ -1,5 +1,6 @@ package net.ripe.rpki.commons.validation; +import lombok.EqualsAndHashCode; import net.ripe.rpki.commons.util.EqualsSupport; import java.io.Serializable; @@ -7,6 +8,7 @@ /** * Captures interesting statistics related to validation. */ +@EqualsAndHashCode public class ValidationMetric extends EqualsSupport implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/main/java/net/ripe/rpki/commons/validation/ValidationResult.java b/src/main/java/net/ripe/rpki/commons/validation/ValidationResult.java index b4abad78..68f0beda 100644 --- a/src/main/java/net/ripe/rpki/commons/validation/ValidationResult.java +++ b/src/main/java/net/ripe/rpki/commons/validation/ValidationResult.java @@ -15,6 +15,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; +import java.util.stream.Collectors; public final class ValidationResult implements Serializable { @@ -195,10 +196,9 @@ public boolean rejectIfNotNull(Object object, String key, String... param) { } public ValidationResult addMetric(String name, String value) { - if (!metrics.containsKey(currentLocation)) { - metrics.put(currentLocation, new ArrayList<>()); - } - metrics.get(currentLocation).add(new ValidationMetric(name, value, DateTimeUtils.currentTimeMillis())); + var metricsForLocation = metrics.computeIfAbsent(currentLocation, (x) -> new ArrayList<>()); + metricsForLocation.add(new ValidationMetric(name, value, DateTimeUtils.currentTimeMillis())); + return this; } @@ -235,15 +235,13 @@ public boolean hasNoFailuresOrWarnings() { } public Set getFailuresForCurrentLocation() { - return new HashSet(getFailures(currentLocation)); + return new HashSet<>(getFailures(currentLocation)); } public List getFailuresForAllLocations() { - List failures = new ArrayList(); - for (ResultsPerLocation checks : results.values()) { - failures.addAll(checks.error); - } - return failures; + return results.values().stream() + .flatMap(location -> location.error.stream()) + .collect(Collectors.toList()); } public List getFailures(ValidationLocation location) { @@ -266,11 +264,9 @@ public boolean hasFailureForLocation(ValidationLocation location) { } public List getWarnings() { - List warnings = new ArrayList(); - for (ResultsPerLocation checks : results.values()) { - warnings.addAll(checks.warning); - } - return warnings; + return results.values().stream() + .flatMap(location -> location.warning.stream()) + .collect(Collectors.toList()); } public List getAllValidationChecksForCurrentLocation() { diff --git a/src/main/java/net/ripe/rpki/commons/validation/roa/RouteOriginValidationPolicy.java b/src/main/java/net/ripe/rpki/commons/validation/roa/RouteOriginValidationPolicy.java index d1dfc3fe..2667a1b5 100644 --- a/src/main/java/net/ripe/rpki/commons/validation/roa/RouteOriginValidationPolicy.java +++ b/src/main/java/net/ripe/rpki/commons/validation/roa/RouteOriginValidationPolicy.java @@ -1,12 +1,10 @@ package net.ripe.rpki.commons.validation.roa; -import lombok.Singular; import lombok.experimental.UtilityClass; import net.ripe.ipresource.IpRange; import net.ripe.ipresource.IpResource; import net.ripe.ipresource.etree.IpResourceIntervalStrategy; import net.ripe.ipresource.etree.NestedIntervalMap; -import net.ripe.rpki.commons.crypto.cms.roa.RoaPrefix; import java.util.LinkedList; import java.util.List; @@ -76,7 +74,7 @@ private static boolean isUnknown(T allowedRoute, IpRan } private static boolean isLengthInvalid(T allowedRoute, IpRange announcedPrefix) { - return !(announcedPrefix.getPrefixLength() <= allowedRoute.getMaximumLength()); + return announcedPrefix.getPrefixLength() > allowedRoute.getMaximumLength(); } private static boolean isAsnInvalid(T allowedRoute, U announcedRoute) {