Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some PMD cleanup #2288

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ protected void logReader(Message message, Reader reader, LoggingMessage buffer)
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();
Expand Down Expand Up @@ -216,11 +216,11 @@ protected void logInputStream(Message message, InputStream is, LoggingMessage bu
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ public void onClose(CachedOutputStream cos) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private UriBuilder doPath(String path, boolean checkSegments) {
// 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(';');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public static String getSetEncoding(MediaType mt, MultivaluedMap<String, Object>
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void buildOperationFunction(StringBuilder parameterList) {

code.append("//\n");

code.append("function "
code.append("function " //NOPMD
+ opFunctionGlobalName
+ "(" + responseCallbackParams
+ ((parameterList.length() > 0 && !currentOperation.isOneWay())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1075,7 +1075,7 @@ protected void handleRepresentation(StringBuilder sb, Set<Class<?>> jaxbTypes,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +129,7 @@ public T getCondition() {
@Override
public ConditionType getConditionType() {
if (scts.size() > 1) {
return joiningType;
return JOINING_TYPE;
}
return scts.get(0).getStatement().getCondition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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;
Expand Down Expand Up @@ -109,7 +109,7 @@ protected List<JweEncryptionProvider> getInitializedEncryptionProviders(List<Str
// 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private boolean compareCredentials(
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public static Cipher initCipher(Key secretKey, KeyProperties keyProps, int mode)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testJWTProviderLifetime() throws Exception {

Instant now = Instant.now();
Long expiry = (Long)jwt.getClaim(JwtConstants.CLAIM_EXPIRY);
Instant.ofEpochSecond(expiry).isAfter(now);
assertTrue(Instant.ofEpochSecond(expiry).isAfter(now));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void testGetWadlFromWadlLocation() throws Exception {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void testRetrieveClaims() throws Exception {
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");
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public void testRetrieveClaimsUsingLDAPLookup() throws Exception {
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");
}
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testMultiUserBaseDNs() throws Exception {
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");
}
}

Expand All @@ -232,7 +232,7 @@ public void testMultiUserBaseDNs() throws Exception {
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");
}
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public void testRetrieveClaimsWithUnsupportedOptionalClaimType() throws Exceptio
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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static TestCaseType getTestCase(String testId) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private Map<String, String> getServiceNames(Binding[] bindings, boolean isDefaul
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ protected static void populateAliasSchemaType(CorbaType corbaType,
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());
}
Expand Down
Loading