Skip to content

Commit f1c4e61

Browse files
authored
GH-10083: Apply Nullability to HTTP module (#10319)
Related to: #10083 The change affects some core classes, since `getBeanName()` cannot be null after a proper bean initialization * Add slight code flow improvement in the `BaseHttpInboundEndpoint` implementations regarding `validate()` method * Fix `DefaultHttpHeaderMapper` tests where a `ConversionService` is required * Fix `StandardIntegrationFlowContext.getBeanName()` for `this.` prefix
1 parent ccd3146 commit f1c4e61

File tree

41 files changed

+236
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+236
-175
lines changed

spring-integration-core/src/main/java/org/springframework/integration/context/ComponentSourceAware.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public interface ComponentSourceAware extends BeanNameAware {
7575
* Return the bean name populated by the {@link BeanNameAware#setBeanName(String)}.
7676
* @return the bean name.
7777
*/
78-
@Nullable
7978
String getBeanName();
8079

8180
}

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public final void setBeanName(String beanName) {
117117
}
118118

119119
@Override
120-
@Nullable
121120
public String getBeanName() {
122121
return this.beanName;
123122
}
@@ -127,7 +126,6 @@ public String getBeanName() {
127126
* If {@link #componentName} was not set this method will default to the 'beanName' of this component;
128127
*/
129128
@Override
130-
@Nullable
131129
public String getComponentName() {
132130
return StringUtils.hasText(this.componentName) ? this.componentName : this.beanName;
133131
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public void setBeanName(String name) {
8080
this.beanName = name;
8181
}
8282

83-
@Nullable
8483
@Override
8584
public String getBeanName() {
8685
return this.beanName;

spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class StandardIntegrationFlow
7676

7777
private @Nullable MessageChannel inputChannel;
7878

79-
private @Nullable boolean running;
79+
private boolean running;
8080

8181
@SuppressWarnings("NullAway.Init")
8282
private String beanName;
@@ -125,7 +125,7 @@ public void setComponentDescription(String description) {
125125
}
126126

127127
@Override
128-
public @Nullable String getBeanName() {
128+
public String getBeanName() {
129129
return this.beanName;
130130
}
131131

spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ private static final class IntegrationFlowComponentSourceAwareAdapter
376376

377377
private final IntegrationFlow delegate;
378378

379+
@SuppressWarnings("NullAway.Init")
380+
private String beanName;
381+
379382
private @Nullable Object beanSource;
380383

381384
private @Nullable String beanDescription;
@@ -404,15 +407,14 @@ public void setComponentDescription(String description) {
404407
return this.beanDescription;
405408
}
406409

407-
@Nullable
408410
@Override
409411
public String getBeanName() {
410-
return null;
412+
return this.beanName;
411413
}
412414

413415
@Override
414416
public void setBeanName(String name) {
415-
417+
this.beanName = name;
416418
}
417419

418420
@Override

spring-integration-core/src/main/java/org/springframework/integration/handler/ControlBusMessageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Object processMessage(Message<?> message) {
7474
@SuppressWarnings("unchecked")
7575
List<Object> arguments =
7676
message.getHeaders().get(IntegrationMessageHeaderAccessor.CONTROL_BUS_ARGUMENTS, List.class);
77-
Class<?>[] parameterTypes = new Class<?>[0];
77+
Class<?>[] parameterTypes = {};
7878
if (!CollectionUtils.isEmpty(arguments)) {
7979
parameterTypes =
8080
arguments.stream()

spring-integration-http/src/main/java/org/springframework/integration/http/config/ControlBusControllerConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
2122

2223
import org.springframework.beans.factory.ObjectProvider;
2324
import org.springframework.beans.factory.config.BeanDefinition;
@@ -42,9 +43,10 @@
4243
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4344
public class ControlBusControllerConfiguration {
4445

45-
private static final Log LOGGER = LogFactory.getLog(IntegrationGraphControllerRegistrar.class);
46+
private static final Log LOGGER = LogFactory.getLog(ControlBusControllerConfiguration.class);
4647

4748
@Bean
49+
@Nullable
4850
ControlBusController controlBusController(ControlBusCommandRegistry controlBusCommandRegistry,
4951
ObjectProvider<FormattingConversionService> conversionService) {
5052

@@ -56,7 +58,7 @@ ControlBusController controlBusController(ControlBusCommandRegistry controlBusCo
5658

5759
controlBusCommandRegistry.setEagerInitialization(true);
5860

59-
return new ControlBusController(controlBusCommandRegistry, conversionService.getIfUnique());
61+
return new ControlBusController(controlBusCommandRegistry, conversionService.getObject());
6062
}
6163

6264
}

spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpContextUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.core.annotation.AnnotationUtils;
2325
import org.springframework.util.ClassUtils;
2426
import org.springframework.util.ObjectUtils;
@@ -85,17 +87,18 @@ private HttpContextUtils() {
8587
* @return the {@link RequestMapping} annotation.
8688
* @since 5.0
8789
*/
88-
public static RequestMapping convertRequestMappingToAnnotation(
90+
public static @Nullable RequestMapping convertRequestMappingToAnnotation(
8991
org.springframework.integration.http.inbound.RequestMapping requestMapping) {
9092

91-
if (ObjectUtils.isEmpty(requestMapping.getPathPatterns())) {
93+
String[] pathPatterns = requestMapping.getPathPatterns();
94+
if (ObjectUtils.isEmpty(pathPatterns)) {
9295
return null;
9396
}
9497

9598
Map<String, Object> requestMappingAttributes = new HashMap<>();
9699
requestMappingAttributes.put("name", requestMapping.getName());
97-
requestMappingAttributes.put("value", requestMapping.getPathPatterns());
98-
requestMappingAttributes.put("path", requestMapping.getPathPatterns());
100+
requestMappingAttributes.put("value", pathPatterns);
101+
requestMappingAttributes.put("path", pathPatterns);
99102
requestMappingAttributes.put("method", requestMapping.getRequestMethods());
100103
requestMappingAttributes.put("params", requestMapping.getParams());
101104
requestMappingAttributes.put("headers", requestMapping.getHeaders());

spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ protected AbstractBeanDefinition parseConsumer(Element element, ParserContext pa
5555
if (StringUtils.hasText(mappedRequestHeaders)) {
5656
parserContext.getReaderContext().error("The 'mapped-request-headers' attribute is not " +
5757
"allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element));
58-
return null;
5958
}
6059
builder.addPropertyReference("headerMapper", headerMapper);
6160
}

spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ protected BeanDefinitionBuilder parseHandler(Element element, ParserContext pars
5858
.error("Neither 'mapped-request-headers' or 'mapped-response-headers' " +
5959
"attributes are allowed when a 'header-mapper' has been specified.",
6060
parserContext.extractSource(element));
61-
return null;
6261
}
6362
builder.addPropertyReference("headerMapper", headerMapper);
6463
}

0 commit comments

Comments
 (0)