Fix new Sonar issues
This commit is contained in:
@@ -34,6 +34,7 @@ import io.vavr.control.Try;
|
||||
* <a href="https://github.com/resilience4j/resilience4j#ratelimiter">Resilience4j</a>.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 5.2
|
||||
*/
|
||||
@@ -126,7 +127,7 @@ public class RateLimiterRequestHandlerAdvice extends AbstractRequestHandlerAdvic
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) {
|
||||
CheckedFunction0<Object> restrictedCall =
|
||||
RateLimiter.decorateCheckedSupplier(this.rateLimiter, callback::execute);
|
||||
try {
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class RateLimiterRequestHandlerAdviceTests {
|
||||
this.requestChannel.send(testMessage);
|
||||
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> this.requestChannel.send(testMessage))
|
||||
.isThrownBy(() -> IntStream.range(0, 10).forEach(i -> this.requestChannel.send(testMessage)))
|
||||
.withCauseInstanceOf(RequestNotPermitted.class)
|
||||
.withMessageContaining("Rate limit exceeded for: ");
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.IgnoreHiddenFileListFilter;
|
||||
import org.springframework.integration.file.filters.RegexPatternFileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -91,6 +92,7 @@ public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<Fil
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public FileListFilter<File> getObject() {
|
||||
if (this.result == null) {
|
||||
synchronized (this.monitor) {
|
||||
|
||||
@@ -116,7 +116,9 @@ public class CompositeFileListFilter<F>
|
||||
}
|
||||
}
|
||||
this.fileFilters.addAll(filtersToAdd);
|
||||
this.allSupportAccept &= filtersToAdd.stream().allMatch(FileListFilter<F>::supportsSingleFileFiltering);
|
||||
if (this.allSupportAccept) {
|
||||
this.allSupportAccept = filtersToAdd.stream().allMatch(FileListFilter<F>::supportsSingleFileFiltering);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
|
||||
for (F file : filteredFiles) {
|
||||
if (filteringOneByOne) {
|
||||
if ((maxFetchSize < 0 || accepted < maxFetchSize) && this.filter.accept(file)) {
|
||||
if ((maxFetchSize < 0 || accepted < maxFetchSize) && this.filter.accept(file)) { // NOSONAR never null
|
||||
accepted++;
|
||||
}
|
||||
else {
|
||||
@@ -342,21 +342,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file,
|
||||
localDirectory, session)) {
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e1) {
|
||||
if (filteringOneByOne) {
|
||||
resetFilterIfNecessary(file);
|
||||
}
|
||||
else {
|
||||
rollbackFromFileToListEnd(filteredFiles, file);
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
copied = copyIfNotNull(localDirectory, session, filteringOneByOne, filteredFiles, copied, file);
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
@@ -365,6 +351,27 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
}
|
||||
}
|
||||
|
||||
private int copyIfNotNull(File localDirectory, Session<F> session, boolean filteringOneByOne, List<F> filteredFiles,
|
||||
int copied, F file) throws IOException {
|
||||
|
||||
try {
|
||||
if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file,
|
||||
localDirectory, session)) {
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e1) {
|
||||
if (filteringOneByOne) {
|
||||
resetFilterIfNecessary(file);
|
||||
}
|
||||
else {
|
||||
rollbackFromFileToListEnd(filteredFiles, file);
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
private List<F> applyFilter(F[] files, boolean haveFilter, boolean filteringOneByOne, int maxFetchSize) {
|
||||
List<F> filteredFiles;
|
||||
if (!filteringOneByOne && haveFilter) {
|
||||
@@ -373,15 +380,13 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
else {
|
||||
filteredFiles = Arrays.asList(files);
|
||||
}
|
||||
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize) {
|
||||
if (!filteringOneByOne) {
|
||||
if (haveFilter) {
|
||||
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
|
||||
}
|
||||
filteredFiles = filteredFiles.stream()
|
||||
.limit(maxFetchSize)
|
||||
.collect(Collectors.toList());
|
||||
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize && !filteringOneByOne) {
|
||||
if (haveFilter) {
|
||||
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
|
||||
}
|
||||
filteredFiles = filteredFiles.stream()
|
||||
.limit(maxFetchSize)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return filteredFiles;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user