Skip to content

Commit d5f97cc

Browse files
committed
Remove Objects.requireNonNull surround this.handler in the AbstractSimpleMessageHandlerFactoryBean
Remove commented code in AbstractSimpleMessageHandlerFactoryBean.extractTarget Restructure IntegrationManagementConfigurer.registerComponentGauges so that a NullAway suppresion can be removed from the method related to: #10083 rebased
1 parent 497d95a commit d5f97cc

File tree

5 files changed

+27
-33
lines changed

5 files changed

+27
-33
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.commons.logging.LogFactory;
2727
import org.jspecify.annotations.Nullable;
2828

29-
import org.springframework.aop.framework.Advised;
3029
import org.springframework.aop.framework.AopProxyUtils;
3130
import org.springframework.beans.BeansException;
3231
import org.springframework.beans.factory.BeanFactory;
@@ -95,7 +94,8 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
9594
@SuppressWarnings("NullAway.Init")
9695
private String beanName;
9796

98-
private @Nullable ApplicationEventPublisher applicationEventPublisher;
97+
@SuppressWarnings("NullAway.Init")
98+
private ApplicationEventPublisher applicationEventPublisher;
9999

100100
private @Nullable DestinationResolver<MessageChannel> channelResolver;
101101

@@ -208,16 +208,16 @@ protected final H createHandlerInternal() {
208208
JavaUtils.INSTANCE
209209
.acceptIfCondition(this.handler instanceof ApplicationContextAware && this.applicationContext != null,
210210
this.applicationContext,
211-
context -> ((ApplicationContextAware) Objects.requireNonNull(this.handler)).setApplicationContext(this.applicationContext))
211+
context -> ((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext))
212212
.acceptIfCondition(this.handler instanceof BeanFactoryAware && getBeanFactory() != null,
213213
getBeanFactory(),
214-
factory -> ((BeanFactoryAware) Objects.requireNonNull(this.handler)).setBeanFactory(factory))
214+
factory -> ((BeanFactoryAware) this.handler).setBeanFactory(factory))
215215
.acceptIfCondition(this.handler instanceof BeanNameAware && this.beanName != null, this.beanName,
216-
name -> ((BeanNameAware) Objects.requireNonNull(this.handler)).setBeanName(this.beanName))
216+
name -> ((BeanNameAware) this.handler).setBeanName(this.beanName))
217217
.acceptIfCondition(this.handler instanceof ApplicationEventPublisherAware
218218
&& this.applicationEventPublisher != null,
219219
this.applicationEventPublisher,
220-
publisher -> ((ApplicationEventPublisherAware) Objects.requireNonNull(Objects.requireNonNull(this.handler)))
220+
publisher -> ((ApplicationEventPublisherAware) this.handler)
221221
.setApplicationEventPublisher(publisher));
222222
configureOutputChannelIfAny();
223223
Object actualHandler = extractTarget(this.handler);
@@ -232,7 +232,7 @@ protected final H createHandlerInternal() {
232232
this.async,
233233
asyncValue -> ((AbstractMessageProducingHandler) handlerToConfigure).setAsync(asyncValue))
234234
.acceptIfCondition(this.handler instanceof Orderable && this.order != null,
235-
this.order, theOrder -> ((Orderable) Objects.requireNonNull(this.handler)).setOrder(theOrder));
235+
this.order, theOrder -> ((Orderable) this.handler).setOrder(theOrder));
236236
this.initialized = true;
237237
}
238238
finally {
@@ -315,14 +315,7 @@ public boolean isSingleton() {
315315
}
316316

317317
private static Object extractTarget(Object object) {
318-
if (!(object instanceof Advised)) {
319-
return object;
320-
}
321-
else {
322-
// return extractTarget(Objects.requireNonNull(AopProxyUtils.getSingletonTarget(object)));
323-
return Objects.requireNonNullElse(AopProxyUtils.getSingletonTarget(object), object);
324-
325-
}
318+
return Objects.requireNonNullElse(AopProxyUtils.getSingletonTarget(object), object);
326319
}
327320

328321
}

spring-integration-core/src/main/java/org/springframework/integration/config/CorrelationStrategyFactoryBean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Method;
2020

2121
import org.jspecify.annotations.NonNull;
22+
import org.jspecify.annotations.Nullable;
2223

2324
import org.springframework.beans.factory.FactoryBean;
2425
import org.springframework.beans.factory.InitializingBean;
@@ -42,7 +43,7 @@ public class CorrelationStrategyFactoryBean implements FactoryBean<CorrelationSt
4243
@SuppressWarnings("NullAway.Init")
4344
private Object target;
4445

45-
@SuppressWarnings("NullAway.Init")
46+
@Nullable
4647
private String methodName;
4748

4849
private CorrelationStrategy strategy =

spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public class DefaultConfiguringBeanFactoryPostProcessor implements BeanDefinitio
8181

8282
private static final Set<Integer> REGISTRIES_PROCESSED = new HashSet<>();
8383

84-
@Nullable
85-
private static final Class<?> XPATH_CLASS;
84+
private static final @Nullable Class<?> XPATH_CLASS;
8685

8786
private static final boolean JSON_PATH_PRESENT = ClassUtils.isPresent("com.jayway.jsonpath.JsonPath", null);
8887

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ public void afterSingletonsInstantiated() {
159159
Assert.state(MANAGEMENT_CONFIGURER_NAME.equals(this.beanName), getClass().getSimpleName()
160160
+ " bean name must be " + MANAGEMENT_CONFIGURER_NAME);
161161

162-
if (obtainMetricsCaptor() != null) {
163-
registerComponentGauges();
162+
MetricsCaptor metricsCaptorToUse = obtainMetricsCaptor();
163+
if (metricsCaptorToUse != null) {
164+
registerComponentGauges(metricsCaptorToUse);
164165
}
165166

166167
setupObservationRegistry();
@@ -185,22 +186,21 @@ private void setupObservationRegistry() {
185186
}
186187
}
187188

188-
@SuppressWarnings("NullAway") // is not called if the metricsCaptor is null in afterSingletonsInstantiated.
189-
private void registerComponentGauges() {
189+
private void registerComponentGauges(MetricsCaptor metricsCaptor) {
190190
this.gauges.add(
191-
this.metricsCaptor.gaugeBuilder("spring.integration.channels", this,
191+
metricsCaptor.gaugeBuilder("spring.integration.channels", this,
192192
(c) -> this.applicationContext.getBeansOfType(MessageChannel.class).size())
193193
.description("The number of message channels")
194194
.build());
195195

196196
this.gauges.add(
197-
this.metricsCaptor.gaugeBuilder("spring.integration.handlers", this,
197+
metricsCaptor.gaugeBuilder("spring.integration.handlers", this,
198198
(c) -> this.applicationContext.getBeansOfType(MessageHandler.class).size())
199199
.description("The number of message handlers")
200200
.build());
201201

202202
this.gauges.add(
203-
this.metricsCaptor.gaugeBuilder("spring.integration.sources", this,
203+
metricsCaptor.gaugeBuilder("spring.integration.sources", this,
204204
(c) -> this.applicationContext.getBeansOfType(MessageSource.class).size())
205205
.description("The number of message sources")
206206
.build());

spring-integration-core/src/main/java/org/springframework/integration/config/SpelFunctionFactoryBean.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Modifier;
2121

22-
import org.jspecify.annotations.Nullable;
23-
2422
import org.springframework.beans.BeanUtils;
2523
import org.springframework.beans.factory.BeanDefinitionStoreException;
2624
import org.springframework.beans.factory.BeanNameAware;
@@ -44,9 +42,11 @@ public class SpelFunctionFactoryBean implements FactoryBean<Method>, Initializin
4442

4543
private final String functionMethodSignature;
4644

47-
private @Nullable String functionName;
45+
@SuppressWarnings("NullAway.Init")
46+
private String functionName;
4847

49-
private @Nullable Method method;
48+
@SuppressWarnings("NullAway.Init")
49+
private Method method;
5050

5151
public SpelFunctionFactoryBean(Class<?> functionClass, String functionMethodSignature) {
5252
this.functionClass = functionClass;
@@ -58,25 +58,26 @@ public void setBeanName(String name) {
5858
this.functionName = name;
5959
}
6060

61-
public @Nullable String getFunctionName() {
61+
public String getFunctionName() {
6262
return this.functionName;
6363
}
6464

6565
@Override
6666
public void afterPropertiesSet() {
67-
this.method = BeanUtils.resolveSignature(this.functionMethodSignature, this.functionClass);
67+
Method method = BeanUtils.resolveSignature(this.functionMethodSignature, this.functionClass);
6868

69-
if (this.method == null) {
69+
if (method == null) {
7070
throw new BeanDefinitionStoreException(String.format("No declared method '%s' in class '%s'",
7171
this.functionMethodSignature, this.functionClass));
7272
}
73+
this.method = method;
7374
if (!Modifier.isStatic(this.method.getModifiers())) {
7475
throw new BeanDefinitionStoreException("SpEL-function method has to be 'static'");
7576
}
7677
}
7778

7879
@Override
79-
public @Nullable Method getObject() {
80+
public Method getObject() {
8081
return this.method;
8182
}
8283

0 commit comments

Comments
 (0)