Skip to content

Commit f1bcd37

Browse files
committed
Issue 10083: Apply Nullability to the project
This change is applicable only to spring-integration-camel. Handled changes in package-info.java. Handled nullable related issues in CamelMessageHandler. Signed-off-by: Anayonkar Shivalkar <[email protected]>
1 parent eb70292 commit f1bcd37

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

spring-integration-camel/src/main/java/org/springframework/integration/camel/dsl/package-info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* Provides supporting classes for JavaDSL with Apache Camel components.
33
*/
44

5-
@org.springframework.lang.NonNullApi
6-
@org.springframework.lang.NonNullFields
5+
@org.jspecify.annotations.NullMarked
76
package org.springframework.integration.camel.dsl;

spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/CamelMessageHandler.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.camel.outbound;
1818

1919
import java.util.Map;
20+
import java.util.Objects;
2021
import java.util.concurrent.CompletableFuture;
2122

2223
import org.apache.camel.CamelContext;
@@ -68,6 +69,7 @@
6869
*/
6970
public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
7071

72+
@Nullable
7173
private ProducerTemplate producerTemplate;
7274

7375
private Expression exchangePatternExpression = new ValueExpression<>(ExchangePattern.InOnly);
@@ -83,6 +85,7 @@ public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
8385
@Nullable
8486
private Expression exchangePropertiesExpression;
8587

88+
@Nullable
8689
private StandardEvaluationContext evaluationContext;
8790

8891
public CamelMessageHandler() {
@@ -197,46 +200,57 @@ public void configure() throws Exception {
197200
}
198201

199202
@Override
203+
@Nullable
200204
protected Object handleRequestMessage(Message<?> requestMessage) {
205+
StandardEvaluationContext localEvaluationContext = Objects.requireNonNull(this.evaluationContext,
206+
"'evaluationContext' must not be null");
201207
ExchangePattern exchangePattern =
202-
this.exchangePatternExpression.getValue(this.evaluationContext, requestMessage, ExchangePattern.class);
208+
this.exchangePatternExpression.getValue(localEvaluationContext, requestMessage, ExchangePattern.class);
203209

204210
Assert.notNull(exchangePattern, "'exchangePatternExpression' must not evaluate to null");
205211

206212
Endpoint endpoint = resolveEndpoint(requestMessage);
207213
Exchange exchange = prepareInExchange(endpoint, exchangePattern, requestMessage);
208214

215+
ProducerTemplate localProducerTemplate = Objects.requireNonNull(this.producerTemplate,
216+
"'producerTemplate' must not be null");
209217
if (isAsync()) {
210-
CompletableFuture<Exchange> result = this.producerTemplate.asyncSend(endpoint, exchange);
218+
CompletableFuture<Exchange> result = localProducerTemplate.asyncSend(endpoint, exchange);
211219
return result.thenApply(resultExchange -> buildReply(exchangePattern, resultExchange));
212220
}
213221
else {
214-
Exchange result = this.producerTemplate.send(endpoint, exchange);
222+
Exchange result = localProducerTemplate.send(endpoint, exchange);
215223
return buildReply(exchangePattern, result);
216224
}
217225
}
218226

219227
private Endpoint resolveEndpoint(Message<?> requestMessage) {
228+
StandardEvaluationContext localEvaluationContext = Objects.requireNonNull(this.evaluationContext,
229+
"'evaluationContext' must not be null");
220230
String endpointUri =
221231
this.endpointUriExpression != null
222-
? this.endpointUriExpression.getValue(this.evaluationContext, requestMessage, String.class)
232+
? this.endpointUriExpression.getValue(localEvaluationContext, requestMessage, String.class)
223233
: null;
224234

235+
ProducerTemplate localProducerTemplate = Objects.requireNonNull(this.producerTemplate,
236+
"'producerTemplate' must not be null");
225237
if (StringUtils.hasText(endpointUri)) {
226-
return this.producerTemplate.getCamelContext().getEndpoint(endpointUri);
238+
return localProducerTemplate.getCamelContext().getEndpoint(endpointUri);
227239
}
228240
else {
229-
return this.producerTemplate.getDefaultEndpoint();
241+
return localProducerTemplate.getDefaultEndpoint();
230242
}
231243
}
232244

233245
@SuppressWarnings("unchecked")
234246
private Exchange prepareInExchange(Endpoint endpoint, ExchangePattern exchangePattern, Message<?> requestMessage) {
235247
Exchange exchange = endpoint.createExchange(exchangePattern);
236248

249+
StandardEvaluationContext localEvaluationContext = Objects.requireNonNull(this.evaluationContext,
250+
"'evaluationContext' must not be null");
237251
Map<String, Object> exchangeProperties =
238252
this.exchangePropertiesExpression != null
239-
? this.exchangePropertiesExpression.getValue(this.evaluationContext, requestMessage, Map.class)
253+
? this.exchangePropertiesExpression.getValue(localEvaluationContext, requestMessage, Map.class)
240254
: null;
241255

242256
if (exchangeProperties != null) {

spring-integration-camel/src/main/java/org/springframework/integration/camel/outbound/package-info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* Provides classes for Apache Camel outbound channel adapters.
33
*/
44

5-
@org.springframework.lang.NonNullApi
6-
@org.springframework.lang.NonNullFields
5+
@org.jspecify.annotations.NullMarked
76
package org.springframework.integration.camel.outbound;

spring-integration-camel/src/main/java/org/springframework/integration/camel/support/package-info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* Provides supporting classes for Apache Camel channel adapters.
33
*/
44

5-
@org.springframework.lang.NonNullApi
6-
@org.springframework.lang.NonNullFields
5+
@org.jspecify.annotations.NullMarked
76
package org.springframework.integration.camel.support;

0 commit comments

Comments
 (0)