diff --git a/spring-integration-core/src/main/java/org/springframework/integration/json/JsonToObjectTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/json/JsonToObjectTransformer.java index 4667a9d377..328be2db8c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/json/JsonToObjectTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/json/JsonToObjectTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -16,6 +16,9 @@ package org.springframework.integration.json; +import java.io.IOException; +import java.io.UncheckedIOException; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.integration.mapping.support.JsonHeaders; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; @@ -79,16 +82,21 @@ public class JsonToObjectTransformer extends AbstractTransformer implements Bean } @Override - protected Object doTransform(Message message) throws Exception { - if (this.targetClass != null) { - return this.jsonObjectMapper.fromJson(message.getPayload(), this.targetClass); + protected Object doTransform(Message message) { + try { + if (this.targetClass != null) { + return this.jsonObjectMapper.fromJson(message.getPayload(), this.targetClass); + } + else { + Object result = this.jsonObjectMapper.fromJson(message.getPayload(), message.getHeaders()); + AbstractIntegrationMessageBuilder messageBuilder = this.getMessageBuilderFactory().withPayload(result) + .copyHeaders(message.getHeaders()) + .removeHeaders(JsonHeaders.HEADERS.toArray(new String[3])); + return messageBuilder.build(); + } } - else { - Object result = this.jsonObjectMapper.fromJson(message.getPayload(), message.getHeaders()); - AbstractIntegrationMessageBuilder messageBuilder = this.getMessageBuilderFactory().withPayload(result) - .copyHeaders(message.getHeaders()) - .removeHeaders(JsonHeaders.HEADERS.toArray(new String[3])); - return messageBuilder.build(); + catch (IOException e) { + throw new UncheckedIOException(e); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/json/ObjectToJsonTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/json/ObjectToJsonTransformer.java index 3f5289c501..92837c8f91 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/json/ObjectToJsonTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/json/ObjectToJsonTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -17,7 +17,9 @@ package org.springframework.integration.json; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.UncheckedIOException; import java.util.Map; import org.springframework.integration.support.json.JsonObjectMapper; @@ -111,7 +113,7 @@ public class ObjectToJsonTransformer extends AbstractTransformer { } @Override - protected Object doTransform(Message message) throws Exception { + protected Object doTransform(Message message) { Object payload = buildJsonPayload(message.getPayload()); Map headers = new LinkedCaseInsensitiveMap<>(); @@ -137,23 +139,28 @@ public class ObjectToJsonTransformer extends AbstractTransformer { .build(); } - private Object buildJsonPayload(Object payload) throws Exception { - switch (this.resultType) { + private Object buildJsonPayload(Object payload) { + try { + switch (this.resultType) { - case STRING: - return this.jsonObjectMapper.toJson(payload); + case STRING: + return this.jsonObjectMapper.toJson(payload); - case NODE: - return this.jsonObjectMapper.toJsonNode(payload); + case NODE: + return this.jsonObjectMapper.toJsonNode(payload); - case BYTES: - try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - this.jsonObjectMapper.toJson(payload, new OutputStreamWriter(baos)); - return baos.toByteArray(); - } + case BYTES: + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + this.jsonObjectMapper.toJson(payload, new OutputStreamWriter(baos)); + return baos.toByteArray(); + } - default: - throw new IllegalArgumentException("Unsupported ResultType provided: " + this.resultType); + default: + throw new IllegalArgumentException("Unsupported ResultType provided: " + this.resultType); + } + } + catch (IOException e) { + throw new UncheckedIOException(e); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java index 680787237b..c818c8774a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java @@ -65,6 +65,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper { + private static final String UNUSED = "unused"; + private final ObjectMapper objectMapper; public Jackson2JsonObjectMapper() { @@ -188,7 +190,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper extends AbstractTransformer { + @Override @SuppressWarnings("unchecked") - public final U doTransform(Message message) throws Exception { + public final U doTransform(Message message) { return this.transformPayload((T) message.getPayload()); } - protected abstract U transformPayload(T payload) throws Exception; + protected abstract U transformPayload(T payload); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractTransformer.java index ad71f8aa8a..2aadecde5b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -53,8 +53,7 @@ public abstract class AbstractTransformer extends IntegrationObjectSupport imple * * @param message The message. * @return The result of the transformation. - * @throws Exception Any exception. */ - protected abstract Object doTransform(Message message) throws Exception; + protected abstract Object doTransform(Message message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckInTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckInTransformer.java index ca3ff8820d..1ea507ec3b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckInTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckInTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -51,7 +51,7 @@ public class ClaimCheckInTransformer extends AbstractTransformer { } @Override - protected Object doTransform(Message message) throws Exception { + protected Object doTransform(Message message) { Assert.notNull(message, "message must not be null"); UUID id = message.getHeaders().getId(); Assert.notNull(id, "ID header must not be null"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckOutTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckOutTransformer.java index 9b9fccc285..981efb8c3c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckOutTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ClaimCheckOutTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -60,7 +60,7 @@ public class ClaimCheckOutTransformer extends AbstractTransformer { } @Override - protected Object doTransform(Message message) throws Exception { + protected Object doTransform(Message message) { Assert.notNull(message, "message must not be null"); Assert.isTrue(message.getPayload() instanceof UUID, "payload must be a UUID"); UUID id = (UUID) message.getPayload(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/DecodingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/DecodingTransformer.java index 90da94bd71..492a7630bc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/DecodingTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/DecodingTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 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. @@ -16,6 +16,9 @@ package org.springframework.integration.transformer; +import java.io.IOException; +import java.io.UncheckedIOException; + import org.springframework.expression.Expression; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.integration.codec.Codec; @@ -79,10 +82,15 @@ public class DecodingTransformer extends AbstractTransformer { } @Override - protected T doTransform(Message message) throws Exception { + protected T doTransform(Message message) { Assert.isTrue(message.getPayload() instanceof byte[], "Message payload must be byte[]"); byte[] bytes = (byte[]) message.getPayload(); - return this.codec.decode(bytes, this.type != null ? this.type : type(message)); + try { + return this.codec.decode(bytes, this.type != null ? this.type : type(message)); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } } @SuppressWarnings("unchecked") diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/EncodingPayloadTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/EncodingPayloadTransformer.java index 336b298341..0108756997 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/EncodingPayloadTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/EncodingPayloadTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2019 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. @@ -16,6 +16,9 @@ package org.springframework.integration.transformer; +import java.io.IOException; +import java.io.UncheckedIOException; + import org.springframework.integration.codec.Codec; import org.springframework.util.Assert; @@ -37,8 +40,13 @@ public class EncodingPayloadTransformer extends AbstractPayloadTransformer> headersToAdd; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MapToObjectTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MapToObjectTransformer.java index 33066417a1..f63d9eef23 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MapToObjectTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MapToObjectTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -76,7 +76,7 @@ public class MapToObjectTransformer extends AbstractPayloadTransformer } @Override - protected Object transformPayload(Map payload) throws Exception { + protected Object transformPayload(Map payload) { Object target = (this.targetClass != null) ? BeanUtils.instantiateClass(this.targetClass) : this.getBeanFactory().getBean(this.targetBeanName); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToMapTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToMapTransformer.java index 6135b6adc8..1fb3991249 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToMapTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToMapTransformer.java @@ -16,6 +16,8 @@ package org.springframework.integration.transformer; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -93,8 +95,14 @@ public class ObjectToMapTransformer extends AbstractPayloadTransformer transformPayload(Object payload) throws Exception { - Map result = this.jsonObjectMapper.fromJson(this.jsonObjectMapper.toJson(payload), Map.class); + protected Map transformPayload(Object payload) { + Map result; + try { + result = this.jsonObjectMapper.fromJson(this.jsonObjectMapper.toJson(payload), Map.class); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } if (this.shouldFlattenKeys) { result = this.flattenMap(result); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToStringTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToStringTransformer.java index aa9ffa8f15..3af4d2758a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToStringTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ObjectToStringTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -16,6 +16,8 @@ package org.springframework.integration.transformer; +import java.io.UnsupportedEncodingException; + import org.springframework.util.Assert; @@ -52,9 +54,14 @@ public class ObjectToStringTransformer extends AbstractPayloadTransformer message) throws Exception { - Assert.isTrue(message.getPayload() instanceof InputStream, "payload must be an InputStream"); - InputStream stream = (InputStream) message.getPayload(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - FileCopyUtils.copy(stream, baos); - Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(message); - if (closeableResource != null) { - closeableResource.close(); + protected Object doTransform(Message message) { + try { + Assert.isTrue(message.getPayload() instanceof InputStream, "payload must be an InputStream"); + InputStream stream = (InputStream) message.getPayload(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + FileCopyUtils.copy(stream, baos); + Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(message); + if (closeableResource != null) { + closeableResource.close(); + } + return this.charset == null ? baos.toByteArray() : baos.toString(this.charset); + } + catch (IOException e) { + throw new UncheckedIOException(e); } - return this.charset == null ? baos.toByteArray() : baos.toString(this.charset); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java index fbdf0b260c..8f996f4d52 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/SyslogToMapTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -62,7 +62,7 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer]+)>(.{15}) ([^ ]+) ([a-zA-Z0-9]{0,32})(.*)", Pattern.DOTALL); @Override - protected Map transformPayload(Object payload) throws Exception { + protected Map transformPayload(Object payload) { boolean isByteArray = payload instanceof byte[]; boolean isString = payload instanceof String; Assert.isTrue(isByteArray || isString, "payload must be String or byte[]"); @@ -80,7 +80,7 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer message) throws Exception { + protected Object doTransform(Message message) { return message; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTransformerTests.java index 7153bb23d2..69fb672cef 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTransformerTests.java @@ -61,9 +61,9 @@ public class PayloadTransformerTests { } @Override - public Integer transformPayload(String s) throws Exception { + public Integer transformPayload(String s) { if (s.equals("bad")) { - throw new Exception("bad input!"); + throw new IllegalStateException("bad input!"); } return s.length(); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index 49eaab4a95..084e83172a 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -352,12 +352,13 @@ public abstract class AbstractInboundFileSynchronizer } private int copyIfNotNull(File localDirectory, Session session, boolean filteringOneByOne, List filteredFiles, - int copied, F file) throws IOException { + int copied, @Nullable F file) throws IOException { + boolean renamedFailed = false; try { if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file, localDirectory, session)) { - copied--; + renamedFailed = false; } } catch (RuntimeException | IOException e1) { @@ -369,7 +370,7 @@ public abstract class AbstractInboundFileSynchronizer } throw e1; } - return copied; + return renamedFailed ? copied - 1 : copied; } private List applyFilter(F[] files, boolean haveFilter, boolean filteringOneByOne, int maxFetchSize) { @@ -483,14 +484,12 @@ public abstract class AbstractInboundFileSynchronizer try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(tempFile))) { session.read(remoteFilePath, outputStream); } + catch (RuntimeException e) { // NOSONAR catch and throw + throw e; + } catch (Exception e) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - else { - throw new MessagingException("Failure occurred while copying '" + remoteFilePath - + "' from the remote to the local directory", e); - } + throw new MessagingException("Failure occurred while copying '" + remoteFilePath + + "' from the remote to the local directory", e); } renamed = tempFile.renameTo(localFile); diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcExecutor.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcExecutor.java index fd57624712..359f9daa82 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcExecutor.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcExecutor.java @@ -56,6 +56,10 @@ import org.springframework.util.Assert; */ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean { + private static final int DEFAULT_CACHE_SIZE = 10; + + private static final float LOAD_FACTOR = 0.75f; + private final DataSource dataSource; private Map> returningResultSetRowMappers = new HashMap<>(0); @@ -64,7 +68,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean { private BeanFactory beanFactory; - private int jdbcCallOperationsCacheSize = 10; + private int jdbcCallOperationsCacheSize = DEFAULT_CACHE_SIZE; private Map jdbcCallOperationsMap; @@ -185,7 +189,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean { } private Map buildJdbcCallOperationsMap() { - return new LinkedHashMap(this.jdbcCallOperationsCacheSize + 1, 0.75f, + return new LinkedHashMap(this.jdbcCallOperationsCacheSize + 1, LOAD_FACTOR, true) { private static final long serialVersionUID = 3801124242820219131L; diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java index 40555cf127..5631357209 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.core.io.Resource; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.file.remote.session.SharedSessionCapable; +import org.springframework.integration.util.JavaUtils; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; @@ -415,40 +416,25 @@ public class DefaultSftpSessionFactory implements SessionFactory, Share } } com.jcraft.jsch.Session jschSession = this.jsch.getSession(this.user, this.host, this.port); - if (this.sessionConfig != null) { - jschSession.setConfig(this.sessionConfig); - } - String pw = this.userInfoWrapper.getPassword(); - if (StringUtils.hasText(pw)) { - jschSession.setPassword(pw); - } + JavaUtils.INSTANCE + .acceptIfNotNull(this.sessionConfig, jschSession::setConfig) + .acceptIfHasText(this.userInfoWrapper.getPassword(), jschSession::setPassword); jschSession.setUserInfo(this.userInfoWrapper); try { - if (this.proxy != null) { - jschSession.setProxy(this.proxy); - } - if (this.socketFactory != null) { - jschSession.setSocketFactory(this.socketFactory); - } if (this.timeout != null) { jschSession.setTimeout(this.timeout); } - if (StringUtils.hasText(this.clientVersion)) { - jschSession.setClientVersion(this.clientVersion); - } - if (StringUtils.hasText(this.hostKeyAlias)) { - jschSession.setHostKeyAlias(this.hostKeyAlias); - } if (this.serverAliveInterval != null) { jschSession.setServerAliveInterval(this.serverAliveInterval); } - if (this.serverAliveCountMax != null) { - jschSession.setServerAliveCountMax(this.serverAliveCountMax); - } - if (this.enableDaemonThread != null) { - jschSession.setDaemonThread(this.enableDaemonThread); - } + JavaUtils.INSTANCE + .acceptIfNotNull(this.proxy, jschSession::setProxy) + .acceptIfNotNull(this.socketFactory, jschSession::setSocketFactory) + .acceptIfHasText(this.clientVersion, jschSession::setClientVersion) + .acceptIfHasText(this.hostKeyAlias, jschSession::setHostKeyAlias) + .acceptIfNotNull(this.serverAliveCountMax, jschSession::setServerAliveCountMax) + .acceptIfNotNull(this.enableDaemonThread, jschSession::setDaemonThread); } catch (Exception e) { throw new BeanCreationException("Attempt to set additional properties of " + diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java index 0ea13a382e..d780f50eaf 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -83,7 +83,7 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa } @Override - public Message fromSyslog(Message message) throws Exception { + public Message fromSyslog(Message message) { Map map = this.transformer.doTransform(message); Map out = new HashMap(); for (Entry entry : map.entrySet()) { diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java index b777a02e96..eab4516209 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -29,5 +29,6 @@ import org.springframework.messaging.Message; @FunctionalInterface public interface MessageConverter { - Message fromSyslog(Message syslog) throws Exception; + Message fromSyslog(Message syslog); + } diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/RFC5424MessageConverter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/RFC5424MessageConverter.java index fbbcc181ac..56e07aadc7 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/RFC5424MessageConverter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/RFC5424MessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2019 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. @@ -16,6 +16,7 @@ package org.springframework.integration.syslog; +import java.io.UnsupportedEncodingException; import java.util.Map; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; @@ -61,13 +62,18 @@ public class RFC5424MessageConverter extends DefaultMessageConverter { @SuppressWarnings("unchecked") @Override - public Message fromSyslog(Message message) throws Exception { + public Message fromSyslog(Message message) { boolean isMap = message.getPayload() instanceof Map; Map map; Object originalContent; if (!isMap) { Assert.isInstanceOf(byte[].class, message.getPayload(), "Only byte[] and Map payloads are supported"); - map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false); + try { + map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false); + } + catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } originalContent = message.getPayload(); } else { diff --git a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java index dd99ce044f..c25277c08b 100644 --- a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java +++ b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java @@ -215,7 +215,7 @@ public class SyslogReceivingChannelAdapterParserTests { public static class PassThruConverter implements MessageConverter { @Override - public Message fromSyslog(Message syslog) throws Exception { + public Message fromSyslog(Message syslog) { return syslog; } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java index f3cf880c42..a2e927afb3 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -16,6 +16,7 @@ package org.springframework.integration.ws; +import java.io.IOException; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -59,7 +60,8 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS return this.headerMapper; } - public void invoke(MessageContext messageContext) throws Exception { + @Override + public void invoke(MessageContext messageContext) throws Exception { // NOSONAR - external interface if (!isRunning()) { throw new ServiceUnavailableException("503 Service Unavailable"); } @@ -116,6 +118,6 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS return this.activeCount.get(); } - protected abstract void doInvoke(MessageContext messageContext) throws Exception; // NOSONAR any exception + protected abstract void doInvoke(MessageContext messageContext) throws IOException; } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java index 146c48fc51..c96e61a457 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -16,6 +16,8 @@ package org.springframework.integration.ws; +import java.io.IOException; + import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.messaging.Message; import org.springframework.oxm.Marshaller; @@ -94,7 +96,7 @@ public class MarshallingWebServiceInboundGateway extends AbstractWebServiceInbou } @Override - protected void doInvoke(MessageContext messageContext) throws Exception { + protected void doInvoke(MessageContext messageContext) throws IOException { WebServiceMessage request = messageContext.getRequest(); Assert.notNull(request, "Invalid message context: request was null."); Object requestObject = MarshallingUtils.unmarshal(this.unmarshaller, request); diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/SimpleWebServiceInboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/SimpleWebServiceInboundGateway.java index 7f9bd5ae92..b60a94383f 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/SimpleWebServiceInboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/SimpleWebServiceInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -49,7 +49,7 @@ public class SimpleWebServiceInboundGateway extends AbstractWebServiceInboundGat } @Override - protected void doInvoke(MessageContext messageContext) throws Exception { + protected void doInvoke(MessageContext messageContext) { WebServiceMessage request = messageContext.getRequest(); Assert.notNull(request, "Invalid message context: request was null."); @@ -85,7 +85,12 @@ public class SimpleWebServiceInboundGateway extends AbstractWebServiceInboundGat "The actual type was [" + replyPayload.getClass().getName() + "]"); } WebServiceMessage response = messageContext.getResponse(); - this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult()); + try { + this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult()); + } + catch (TransformerException e) { + throw new IllegalStateException(e); + } toSoapHeaders(response, replyMessage); } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java index 2524caf81b..d2db5cef94 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java @@ -86,7 +86,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { private Properties outputProperties; - private boolean iterator = true; + private boolean returnIterator = true; public XPathMessageSplitter(String expression) { this(expression, new HashMap<>()); @@ -182,7 +182,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { * @since 4.2 */ public void setIterator(boolean iterator) { - this.iterator = iterator; + this.returnIterator = iterator; } /** @@ -200,9 +200,9 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { @Override protected void doInit() { super.doInit(); - if (this.iterator && this.jaxpExpression == null) { + if (this.returnIterator && this.jaxpExpression == null) { logger.info("The 'iterator' option isn't available for an external XPathExpression. Will be ignored"); - this.iterator = false; + this.returnIterator = false; } } @@ -246,7 +246,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { } @SuppressWarnings("unchecked") - private Object splitDocument(Document document) throws Exception { + private Object splitDocument(Document document) throws ParserConfigurationException, TransformerException { Object nodes = splitNode(document); final Transformer transformer; synchronized (this.transformerFactory) { @@ -282,7 +282,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { } private Object splitNode(Node node) throws ParserConfigurationException { - if (this.iterator) { + if (this.returnIterator) { try { NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET); return new NodeListIterator(nodeList); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XPathTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XPathTransformer.java index 7c20563013..97213349cc 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XPathTransformer.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XPathTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -112,7 +112,7 @@ public class XPathTransformer extends AbstractTransformer { } @Override - protected Object doTransform(Message message) throws Exception { + protected Object doTransform(Message message) { Node node = this.converter.convertToNode(message.getPayload()); Object result = null; if (this.nodeMapper != null) { diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XsltPayloadTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XsltPayloadTransformer.java index 1e2d1f5865..10f4c563a6 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XsltPayloadTransformer.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XsltPayloadTransformer.java @@ -250,7 +250,7 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be try { transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file,jar:file"); } - catch (IllegalArgumentException ex) { + catch (@SuppressWarnings("unused") IllegalArgumentException ex) { if (logger.isInfoEnabled()) { logger.info("The '" + XMLConstants.ACCESS_EXTERNAL_STYLESHEET + "' property is not supported by " + transformerFactory.getClass().getCanonicalName()); @@ -260,33 +260,38 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be } @Override - protected Object doTransform(Message message) throws Exception { - Transformer transformer = buildTransformer(message); - Object payload; - if (this.alwaysUseSourceFactory) { - payload = this.sourceFactory.createSource(message.getPayload()); + protected Object doTransform(Message message) { + try { + Transformer transformer = buildTransformer(message); + Object payload; + if (this.alwaysUseSourceFactory) { + payload = this.sourceFactory.createSource(message.getPayload()); + } + else { + payload = message.getPayload(); + } + Object transformedPayload = null; + if (this.alwaysUseResultFactory) { + transformedPayload = transformUsingResultFactory(payload, transformer); + } + else if (payload instanceof String) { + transformedPayload = transformString((String) payload, transformer); + } + else if (payload instanceof Document) { + transformedPayload = transformDocument((Document) payload, transformer); + } + else if (payload instanceof Source) { + transformedPayload = transformSource((Source) payload, payload, transformer); + } + else { + // fall back to trying factories + transformedPayload = transformUsingResultFactory(payload, transformer); + } + return transformedPayload; } - else { - payload = message.getPayload(); + catch (TransformerException e) { + throw new IllegalStateException(e); } - Object transformedPayload = null; - if (this.alwaysUseResultFactory) { - transformedPayload = transformUsingResultFactory(payload, transformer); - } - else if (payload instanceof String) { - transformedPayload = transformString((String) payload, transformer); - } - else if (payload instanceof Document) { - transformedPayload = transformDocument((Document) payload, transformer); - } - else if (payload instanceof Source) { - transformedPayload = transformSource((Source) payload, payload, transformer); - } - else { - // fall back to trying factories - transformedPayload = transformUsingResultFactory(payload, transformer); - } - return transformedPayload; } private Object transformUsingResultFactory(Object payload, Transformer transformer) throws TransformerException { diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathSplitterParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathSplitterParserTests.java index 9ad095d97f..48c80440aa 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathSplitterParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathSplitterParserTests.java @@ -61,7 +61,7 @@ public class XPathSplitterParserTests { public void testXpathSplitterConfig() { assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "createDocuments", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "applySequence", Boolean.class)).isFalse(); - assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "iterator", Boolean.class)).isFalse(); + assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "returnIterator", Boolean.class)).isFalse(); assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "outputProperties")).isSameAs(this.outputProperties); assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "xpathExpression.xpathExpression.xpath.m_patternString", diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java index 1884b854fb..6e21375c8a 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java @@ -60,7 +60,7 @@ import org.springframework.xml.transform.StringSource; */ public class XsltPayloadTransformerTests { - private XsltPayloadTransformer transformer; + private XsltPayloadTransformer testTransformer; private final String docAsString = "test"; @@ -72,16 +72,16 @@ public class XsltPayloadTransformerTests { @Before public void setUp() throws Exception { - this.transformer = new XsltPayloadTransformer(getXslTemplates()); - this.transformer.setBeanFactory(Mockito.mock(BeanFactory.class)); - this.transformer.setAlwaysUseResultFactory(false); - this.transformer.afterPropertiesSet(); + this.testTransformer = new XsltPayloadTransformer(getXslTemplates()); + this.testTransformer.setBeanFactory(Mockito.mock(BeanFactory.class)); + this.testTransformer.setAlwaysUseResultFactory(false); + this.testTransformer.afterPropertiesSet(); } @Test public void testDocumentAsPayload() throws Exception { Message message = new GenericMessage<>(XmlTestUtil.getDocumentForString(this.docAsString)); - Object transformed = this.transformer.doTransform(message); + Object transformed = this.testTransformer.doTransform(message); assertThat(transformed) .as("Wrong return type for document payload") .isInstanceOf(Document.class); @@ -92,7 +92,7 @@ public class XsltPayloadTransformerTests { @Test public void testSourceAsPayload() throws Exception { GenericMessage message = new GenericMessage<>(new StringSource(this.docAsString)); - Object transformed = transformer.doTransform(message); + Object transformed = testTransformer.doTransform(message); assertThat(transformed) .as("Wrong return type for document payload") @@ -105,8 +105,8 @@ public class XsltPayloadTransformerTests { } @Test - public void testStringAsPayload() throws Exception { - Object transformed = this.transformer.doTransform(new GenericMessage<>(this.docAsString)); + public void testStringAsPayload() { + Object transformed = this.testTransformer.doTransform(new GenericMessage<>(this.docAsString)); assertThat(transformed) .as("Wrong return type for document payload") @@ -120,8 +120,8 @@ public class XsltPayloadTransformerTests { @Test public void testStringAsPayloadUseResultFactoryTrue() throws Exception { - this.transformer.setAlwaysUseResultFactory(true); - Object transformed = transformer.doTransform(new GenericMessage<>(this.docAsString)); + this.testTransformer.setAlwaysUseResultFactory(true); + Object transformed = testTransformer.doTransform(new GenericMessage<>(this.docAsString)); assertThat(transformed) .as("Wrong return type for useFactories true") @@ -171,18 +171,19 @@ public class XsltPayloadTransformerTests { @Test public void testNonXmlString() { - assertThatExceptionOfType(TransformerException.class) - .isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>("test"))); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> this.testTransformer.doTransform(new GenericMessage<>("test"))) + .withCauseInstanceOf(TransformerException.class); } @Test public void testUnsupportedPayloadType() { assertThatExceptionOfType(MessagingException.class) - .isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>(12))); + .isThrownBy(() -> this.testTransformer.doTransform(new GenericMessage<>(12))); } @Test - public void testXsltWithImports() throws Exception { + public void testXsltWithImports() { Resource resource = new ClassPathResource("transform-with-import.xsl", getClass()); XsltPayloadTransformer transformer = new XsltPayloadTransformer(resource); transformer.setBeanFactory(Mockito.mock(BeanFactory.class)); @@ -271,6 +272,7 @@ public class XsltPayloadTransformerTests { this.objectToReturn = objectToReturn; } + @Override public Object transformResult(Result result) { return objectToReturn; } diff --git a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java index 613ac21ccb..9b023b51a5 100644 --- a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java +++ b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java @@ -21,6 +21,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.util.XmppStringUtils; import org.springframework.beans.factory.BeanInitializationException; @@ -134,7 +135,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean() { - - @Override - public Boolean call() throws Exception { + future = this.mutexTaskExecutor.submit(() -> { + try { return ZkLock.this.client.checkExists().forPath("/") != null; } - + catch (Exception e) { + throw new IllegalStateException(e); + } }); long waitTime = unit.toMillis(time); @@ -300,10 +299,16 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB return this.mutex.acquire(waitTime, TimeUnit.MILLISECONDS); } } - catch (TimeoutException e) { - future.cancel(true); + catch (@SuppressWarnings("unused") TimeoutException e) { + if (future != null) { + future.cancel(true); + } return false; } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } catch (Exception e) { throw new MessagingException("Failed to acquire mutex at " + this.path, e); } diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index 6443c01a61..b635d02af9 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 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. @@ -48,6 +48,8 @@ import org.springframework.util.Assert; */ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle { + private static final String UNUSED = "unused"; + private final Object lifecycleMonitor = new Object(); private final CuratorFramework client; @@ -120,14 +122,15 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif createNode(key, value); return null; } - catch (KeeperException.NodeExistsException e) { + catch (@SuppressWarnings(UNUSED) KeeperException.NodeExistsException e) { // so the data actually exists, we can read it try { byte[] bytes = this.client.getData().forPath(getPath(key)); return IntegrationUtils.bytesToString(bytes, this.encoding); } catch (Exception exceptionDuringGet) { - throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e); + throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", + exceptionDuringGet); } } catch (Exception e) { @@ -150,16 +153,16 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } return true; } - catch (KeeperException.NoNodeException e) { + catch (@SuppressWarnings(UNUSED) KeeperException.NoNodeException e) { // ignore, the node doesn't exist there's nothing to replace return false; } - catch (KeeperException.BadVersionException e) { + catch (@SuppressWarnings(UNUSED) KeeperException.BadVersionException e) { // ignore return false; } catch (Exception e) { - throw new ZookeeperMetadataStoreException("Cannot replace value"); + throw new ZookeeperMetadataStoreException("Cannot replace value", e); } } } @@ -186,7 +189,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif try { createNode(key, value); } - catch (KeeperException.NodeExistsException e) { + catch (@SuppressWarnings(UNUSED) KeeperException.NodeExistsException e) { updateNode(key, value, -1); } } @@ -240,7 +243,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif this.updateMap.put(key, new LocalChildData(null, Integer.MAX_VALUE)); return IntegrationUtils.bytesToString(bytes, this.encoding); } - catch (KeeperException.NoNodeException e) { + catch (@SuppressWarnings(UNUSED) KeeperException.NoNodeException e) { // ignore - the node doesn't exist return null; } @@ -250,13 +253,13 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } } - private void updateNode(String key, String value, int version) throws Exception { + private void updateNode(String key, String value, int version) throws Exception { // NOSONAR external lib throws Stat stat = this.client.setData().withVersion(version).forPath(getPath(key), IntegrationUtils.stringToBytes(value, this.encoding)); this.updateMap.put(key, new LocalChildData(value, stat.getVersion())); } - private void createNode(String key, String value) throws Exception { + private void createNode(String key, String value) throws Exception { // NOSONAR external lib throws this.client.create().forPath(getPath(key), IntegrationUtils.stringToBytes(value, this.encoding)); this.updateMap.put(key, new LocalChildData(value, 0)); } @@ -359,7 +362,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } @Override - public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { + public void childEvent(CuratorFramework framework, PathChildrenCacheEvent event) { synchronized (ZookeeperMetadataStore.this.updateMap) { String eventPath = event.getData().getPath(); String eventKey = getKey(eventPath);