Fix new Sonar smells

This commit is contained in:
Artem Bilan
2021-02-03 10:54:30 -05:00
parent e847570b85
commit 88d2bebb9c
3 changed files with 61 additions and 46 deletions

View File

@@ -975,13 +975,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
boolean recursion, F file) throws IOException {
String fileName = getFilename(file);
String fileSeparator = this.remoteFileTemplate.getRemoteFileSeparator();
final boolean isDirectory = isDirectory(file);
boolean isDots =
".".equals(fileName)
|| "..".equals(fileName)
|| fileName.endsWith(fileSeparator + ".")
|| fileName.endsWith(fileSeparator + "..");
boolean isDots = hasDots(fileName);
if ((this.options.contains(Option.SUBDIRS) || !isDirectory)
&& (!isDots || this.options.contains(Option.ALL))) {
@@ -993,10 +988,19 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
}
if (recursion && isDirectory && !isDots) {
lsFiles.addAll(listFilesInRemoteDir(session, directory, subDirectory + fileName + fileSeparator));
lsFiles.addAll(listFilesInRemoteDir(session, directory, subDirectory + fileName +
this.remoteFileTemplate.getRemoteFileSeparator()));
}
}
private boolean hasDots(String fileName) {
String fileSeparator = this.remoteFileTemplate.getRemoteFileSeparator();
return ".".equals(fileName)
|| "..".equals(fileName)
|| fileName.endsWith(fileSeparator + ".")
|| fileName.endsWith(fileSeparator + "..");
}
protected final List<File> filterMputFiles(File[] files) {
if (files == null) {
return Collections.emptyList();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,8 +74,8 @@ public class PollableJmsChannel extends AbstractJmsChannel
Deque<ChannelInterceptor> interceptorStack = null;
boolean counted = false;
try {
if (isLoggingEnabled() && logger.isTraceEnabled()) {
logger.trace("preReceive on channel '" + this + "'");
if (isLoggingEnabled()) {
logger.trace(() -> "preReceive on channel '" + this + "'");
}
if (interceptorList.getInterceptors().size() > 0) {
interceptorStack = new ArrayDeque<>();
@@ -84,35 +84,13 @@ public class PollableJmsChannel extends AbstractJmsChannel
return null;
}
}
Object object;
if (this.messageSelector == null) {
object = getJmsTemplate().receiveAndConvert();
}
else {
object = getJmsTemplate().receiveSelectedAndConvert(this.messageSelector);
}
Message<?> message = null;
if (object == null) {
if (isLoggingEnabled() && logger.isTraceEnabled()) {
logger.trace("postReceive on channel '" + this + "', message is null");
}
}
else {
Message<?> message = receiveAndConvertToMessage();
if (message != null) {
incrementReceiveCounter();
counted = true;
if (object instanceof Message<?>) {
message = (Message<?>) object;
}
else {
message = getMessageBuilderFactory()
.withPayload(object)
.build();
}
if (isLoggingEnabled() && logger.isDebugEnabled()) {
logger.debug("postReceive on channel '" + this + "', message: " + message);
}
}
if (interceptorStack != null && message != null) {
message = interceptorList.postReceive(message, this);
}
@@ -128,6 +106,39 @@ public class PollableJmsChannel extends AbstractJmsChannel
}
}
@Nullable
private Message<?> receiveAndConvertToMessage() {
Object object;
if (this.messageSelector == null) {
object = getJmsTemplate().receiveAndConvert();
}
else {
object = getJmsTemplate().receiveSelectedAndConvert(this.messageSelector);
}
if (object == null) {
if (isLoggingEnabled()) {
logger.trace(() -> "postReceive on channel '" + this + "', message is null");
}
return null;
}
else {
Message<?> message;
if (object instanceof Message<?>) {
message = (Message<?>) object;
}
else {
message = getMessageBuilderFactory()
.withPayload(object)
.build();
}
if (isLoggingEnabled()) {
logger.debug(() -> "postReceive on channel '" + this + "', message: " + message);
}
return message;
}
}
private void incrementReceiveCounter() {
MetricsCaptor metricsCaptor = getMetricsCaptor();
if (metricsCaptor != null) {

View File

@@ -16,6 +16,9 @@
package org.springframework.integration.jpa.config.xml;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -87,21 +90,18 @@ public class RetrievingJpaOutboundGatewayParser extends AbstractJpaOutboundGatew
String[] otherAttributes = { "jpa-query", "native-query", "named-query", "first-result",
"first-result-expression", "max-results", "max-results-expression", "delete-in-batch",
"expect-single-result", "parameter-source-factory", "use-payload-as-parameter-source" };
StringBuilder others = new StringBuilder();
for (String otherAttribute : otherAttributes) {
if (gatewayElement.hasAttribute(otherAttribute) &&
StringUtils.hasText(gatewayElement.getAttribute(otherAttribute))) {
if (others.length() > 0) {
others.append(", ");
}
others.append(otherAttribute);
}
}
String others =
Arrays.stream(otherAttributes)
.filter((attr) -> gatewayElement.hasAttribute(attr) &&
StringUtils.hasText(gatewayElement.getAttribute(attr)))
.collect(Collectors.joining(","));
boolean childElementsExist = !CollectionUtils.isEmpty(DomUtils.getChildElementsByTagName(gatewayElement,
"parameter"));
if (others.length() > 0 || childElementsExist) {
parserContext.getReaderContext().error(
(others.length() == 0 ? "" : "'" + others.toString() + "' "
(others.length() == 0 ? "" : "'" + others + "' "
+ (childElementsExist ? "and " : ""))
+ (childElementsExist ? "child elements " : "")
+ "not allowed with an 'id-expression' attribute.",