You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2025/02/24 14:51:36 UTC
(cxf) 01/01: Some PMD cleanup
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch coheigea/pmd-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 116fe6a89c2d40b003c3e8c81ab0d1dff4edecc3
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Feb 24 14:51:17 2025 +0000
Some PMD cleanup
---
.../java/org/apache/cxf/interceptor/LoggingInInterceptor.java | 8 ++++----
.../java/org/apache/cxf/interceptor/LoggingOutInterceptor.java | 6 +++---
.../main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java | 2 +-
.../src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java | 2 +-
.../cxf/javascript/service/ServiceJavascriptBuilder.java | 2 +-
.../java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java | 4 ++--
.../org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java | 4 ++--
.../rs/security/jose/jaxrs/AbstractJweJsonWriterProvider.java | 4 ++--
.../org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java | 2 +-
.../java/org/apache/cxf/rt/security/crypto/CryptoUtils.java | 2 +-
.../apache/cxf/sts/token/provider/JWTProviderLifetimeTest.java | 2 +-
.../cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java | 2 +-
.../java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java | 10 +++++-----
.../java/org/apache/cxf/jms/testsuite/util/JMSTestUtil.java | 2 +-
.../cxf/tools/corba/processors/idl/IDLToWSDLProcessor.java | 2 +-
.../cxf/tools/corba/processors/idl/ScopedNameVisitor.java | 2 +-
16 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
index 48feaf2038..5b1d6a36e8 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
@@ -177,10 +177,10 @@ public class LoggingInInterceptor extends AbstractLoggingInterceptor {
if (writer.getTempFile() != null) {
//large thing on disk...
buffer.getMessage().append("\nMessage (saved to tmp file):\n");
- buffer.getMessage().append("Filename: " + writer.getTempFile().getAbsolutePath() + "\n");
+ buffer.getMessage().append("Filename: ").append(writer.getTempFile().getAbsolutePath()).append('\n');
}
if (writer.size() > limit && limit != -1) {
- buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
+ buffer.getMessage().append("(message truncated to ").append(limit).append(" bytes)\n");
}
writer.writeCacheTo(buffer.getPayload(), limit);
writer.close();
@@ -216,11 +216,11 @@ public class LoggingInInterceptor extends AbstractLoggingInterceptor {
if (bos.getTempFile() != null) {
//large thing on disk...
buffer.getMessage().append("\nMessage (saved to tmp file):\n");
- buffer.getMessage().append("Filename: " + bos.getTempFile().getAbsolutePath() + "\n");
+ buffer.getMessage().append("Filename: ").append(bos.getTempFile().getAbsolutePath()).append('\n');
}
boolean truncated = false;
if (bos.size() > limit && limit != -1) {
- buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
+ buffer.getMessage().append("(message truncated to ").append(limit).append(" bytes)\n");
truncated = true;
}
writePayload(buffer.getPayload(), bos, encoding, ct, truncated);
diff --git a/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
index 0f9ef6e0af..2d70b6589b 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
@@ -236,14 +236,14 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor {
if (cos.getTempFile() == null) {
//buffer.append("Outbound Message:\n");
if (cos.size() >= lim) {
- buffer.getMessage().append("(message truncated to " + lim + " bytes)\n");
+ buffer.getMessage().append("(message truncated to ").append(lim).append(" bytes)\n");
truncated = true;
}
} else {
buffer.getMessage().append("Outbound Message (saved to tmp file):\n");
- buffer.getMessage().append("Filename: " + cos.getTempFile().getAbsolutePath() + "\n");
+ buffer.getMessage().append("Filename: ").append(cos.getTempFile().getAbsolutePath()).append('\n');
if (cos.size() >= lim) {
- buffer.getMessage().append("(message truncated to " + lim + " bytes)\n");
+ buffer.getMessage().append("(message truncated to ").append(lim).append(" bytes)\n");
truncated = true;
}
}
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
index 3313247ebe..31933b3e97 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
@@ -563,7 +563,7 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
// such empty paths having matrix parameters...
int schemeIndex = pathEncoded.indexOf("//");
if (schemeIndex != -1) {
- int pathComponentStart = pathEncoded.indexOf("/", schemeIndex + 2);
+ int pathComponentStart = pathEncoded.indexOf('/', schemeIndex + 2);
if (pathComponentStart == -1) {
this.originalPathEmpty = true;
pathComponentStart = pathEncoded.indexOf(';');
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index 083871e764..58bbf306fc 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -602,7 +602,7 @@ public final class HttpUtils {
return defaultEncoding;
}
try {
- "0".getBytes(enc);
+ "0".getBytes(enc); //NOPMD
return enc;
} catch (UnsupportedEncodingException ex) {
String message = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_ENCODING",
diff --git a/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java b/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
index e2664dca61..9b46f82539 100755
--- a/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
+++ b/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
@@ -338,7 +338,7 @@ public class ServiceJavascriptBuilder extends ServiceModelVisitor {
code.append("//\n");
- code.append("function "
+ code.append("function " //NOPMD
+ opFunctionGlobalName
+ "(" + responseCallbackParams
+ ((parameterList.length() > 0 && !currentOperation.isOneWay())
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 897a2ffbb1..881e29dcc1 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -153,6 +153,7 @@ public class WadlGenerator implements ContainerRequestFilter {
private static final String JAXB_DEFAULT_NAME = "##default";
private static final String CLASSPATH_PREFIX = "classpath:";
private static final String DEFAULT_NS_PREFIX = "prefix";
+ private static final MediaType DEFAULT_REP_MEDIA_TYPE = MediaType.WILDCARD_TYPE;
private static final Map<ParameterType, Class<? extends Annotation>> PARAMETER_TYPE_MAP;
static {
PARAMETER_TYPE_MAP = new EnumMap<>(ParameterType.class);
@@ -195,7 +196,6 @@ public class WadlGenerator implements ContainerRequestFilter {
private String applicationTitle;
private String nsPrefix = DEFAULT_NS_PREFIX;
private MediaType defaultWadlResponseMediaType = MediaType.APPLICATION_XML_TYPE;
- private final MediaType defaultRepMediaType = MediaType.WILDCARD_TYPE;
private String stylesheetReference;
private boolean applyStylesheetLocally;
private Bus bus;
@@ -1075,7 +1075,7 @@ public class WadlGenerator implements ContainerRequestFilter {
if (MultivaluedMap.class.isAssignableFrom(type)) {
types = Collections.singletonList(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
} else if (isWildcard(types)) {
- types = Collections.singletonList(defaultRepMediaType);
+ types = Collections.singletonList(DEFAULT_REP_MEDIA_TYPE);
}
Method opMethod = getMethod(ori);
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
index 19b6ba097a..683473b4e3 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
@@ -50,7 +50,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T> {
SUPPORTED_TYPES.add(ConditionType.LESS_THAN);
SUPPORTED_TYPES.add(ConditionType.LESS_OR_EQUALS);
}
- private final ConditionType joiningType = ConditionType.AND;
+ private static final ConditionType JOINING_TYPE = ConditionType.AND;
private T condition;
private List<SearchCondition<T>> scts;
@@ -129,7 +129,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T> {
@Override
public ConditionType getConditionType() {
if (scts.size() > 1) {
- return joiningType;
+ return JOINING_TYPE;
}
return scts.get(0).getStatement().getCondition();
}
diff --git a/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/AbstractJweJsonWriterProvider.java b/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/AbstractJweJsonWriterProvider.java
index ec6b16588e..1b77075613 100644
--- a/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/AbstractJweJsonWriterProvider.java
+++ b/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/AbstractJweJsonWriterProvider.java
@@ -24,7 +24,7 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashSet;
+import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -109,7 +109,7 @@ public class AbstractJweJsonWriterProvider {
// This set is to find out how many key encryption algorithms are used
// If only one then save it in the shared protected headers as opposed to
// per-recipient specific not protected ones
- Set<KeyAlgorithm> keyAlgos = new HashSet<>();
+ Set<KeyAlgorithm> keyAlgos = EnumSet.noneOf(KeyAlgorithm.class);
List<KeyEncryptionProvider> keyProviders = new LinkedList<>();
for (int i = 0; i < propLocs.size(); i++) {
diff --git a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java
index 9f29614b2f..74144fc3e7 100644
--- a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java
+++ b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/AbstractSamlInHandler.java
@@ -337,7 +337,7 @@ public abstract class AbstractSamlInHandler implements ContainerRequestFilter {
if (tlsCerts != null && tlsCerts.length > 0 && subjectCerts != null
&& subjectCerts.length > 0 && tlsCerts[0].equals(subjectCerts[0])) {
return true;
- } else if (tlsCerts != null && tlsCerts.length > 0 && subjectPublicKey != null
+ } else if (tlsCerts != null && tlsCerts.length > 0
&& tlsCerts[0].getPublicKey().equals(subjectPublicKey)) {
return true;
}
diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
index a5adba572f..2696401795 100644
--- a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
+++ b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
@@ -581,7 +581,7 @@ public final class CryptoUtils {
if (algorithm.equals("AESWrap")) {
int keySize = secretKey.getEncoded().length;
algorithm = "AESWrap_" + keySize * 8;
- secretKey = new SecretKeySpec(secretKey.getEncoded(), 0, keySize, "AES");
+ secretKey = new SecretKeySpec(secretKey.getEncoded(), 0, keySize, "AES"); //NOPMD - false positive
}
Cipher c = Cipher.getInstance(algorithm);
if (keyProps == null || keyProps.getAlgoSpec() == null && keyProps.getSecureRandom() == null) {
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/JWTProviderLifetimeTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/JWTProviderLifetimeTest.java
index 7e297bdf7a..8339ee294c 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/JWTProviderLifetimeTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/JWTProviderLifetimeTest.java
@@ -124,7 +124,7 @@ public class JWTProviderLifetimeTest {
Instant now = Instant.now();
Long expiry = (Long)jwt.getClaim(JwtConstants.CLAIM_EXPIRY);
- Instant.ofEpochSecond(expiry).isAfter(now);
+ assertTrue(Instant.ofEpochSecond(expiry).isAfter(now));
}
/**
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index 4a609d4123..ff61f02e3f 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -286,7 +286,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
String piData = ((ProcessingInstruction)n).getData();
int hRefStart = piData.indexOf("href=\"");
if (hRefStart > 0) {
- int hRefEnd = piData.indexOf("\"", hRefStart + 6);
+ int hRefEnd = piData.indexOf('"', hRefStart + 6);
templateRef = piData.substring(hRefStart + 6, hRefEnd);
}
}
diff --git a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java
index d259a0d700..138afcd11d 100644
--- a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java
+++ b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java
@@ -138,7 +138,7 @@ public class LDAPClaimsTest {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
- Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
+ Assert.fail("Claim '" + c.getClaimType() + "' not requested");
}
}
}
@@ -171,7 +171,7 @@ public class LDAPClaimsTest {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
- Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
+ Assert.fail("Claim '" + c.getClaimType() + "' not requested");
}
}
}
@@ -210,7 +210,7 @@ public class LDAPClaimsTest {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
- Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
+ Assert.fail("Claim '" + c.getClaimType() + "' not requested");
}
}
@@ -232,7 +232,7 @@ public class LDAPClaimsTest {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
- Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
+ Assert.fail("Claim '" + c.getClaimType() + "' not requested");
}
}
}
@@ -295,7 +295,7 @@ public class LDAPClaimsTest {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
- Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
+ Assert.fail("Claim '" + c.getClaimType() + "' not requested");
}
}
}
diff --git a/systests/transport-jms/src/test/java/org/apache/cxf/jms/testsuite/util/JMSTestUtil.java b/systests/transport-jms/src/test/java/org/apache/cxf/jms/testsuite/util/JMSTestUtil.java
index 27791ed2f8..46c3fd7fa3 100644
--- a/systests/transport-jms/src/test/java/org/apache/cxf/jms/testsuite/util/JMSTestUtil.java
+++ b/systests/transport-jms/src/test/java/org/apache/cxf/jms/testsuite/util/JMSTestUtil.java
@@ -84,7 +84,7 @@ public final class JMSTestUtil {
private static void loadTestCases() throws Exception {
JAXBContext context = JAXBContext.newInstance("org.apache.cxf.testsuite.testcase");
Unmarshaller unmarshaller = context.createUnmarshaller();
- JAXBElement<?> e = (JAXBElement<?>)unmarshaller.unmarshal(new JMSTestUtil().getClass()
+ JAXBElement<?> e = (JAXBElement<?>)unmarshaller.unmarshal(JMSTestUtil.class
.getResource("/org/apache/cxf/jms/testsuite/util/testcases.xml"));
testcases = (TestCasesType)e.getValue();
}
diff --git a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/IDLToWSDLProcessor.java b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/IDLToWSDLProcessor.java
index 538ed2f639..9ec42ef7d4 100644
--- a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/IDLToWSDLProcessor.java
+++ b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/IDLToWSDLProcessor.java
@@ -436,7 +436,7 @@ public class IDLToWSDLProcessor extends IDLProcessor {
for (int j = 0; j < bindingTokens.length - 2; j++) {
name.append(bindingTokens[j]).append('.');
}
- name.append(bindingTokens[bindingTokens.length - 2] + "CORBAService");
+ name.append(bindingTokens[bindingTokens.length - 2]).append("CORBAService");
serviceNames.put(ns, name.toString());
} else {
serviceNames.put(ns, idl + "CORBAService");
diff --git a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java
index 8042777293..299ad4ac5b 100644
--- a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java
+++ b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java
@@ -622,7 +622,7 @@ public class ScopedNameVisitor extends VisitorBase {
Alias alias = (Alias) corbaType;
//loop through alias base types, till you get a non-alias corba type
CorbaType type = findCorbaType(typeMap, alias.getBasetype());
- while ((type != null) && type instanceof Alias) {
+ while (type instanceof Alias) {
alias = (Alias) type;
type = findCorbaType(typeMap, alias.getBasetype());
}