Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Artem Bilan
* @author Stephane Nicoll
* @author Steve Singer
* @author Glenn Renfro
*
* @since 2.1
*/
Expand Down Expand Up @@ -107,8 +108,8 @@ protected DefaultAmqpHeaderMapper(String @Nullable [] requestHeaderNames, String
* Extract "standard" headers from an AMQP MessageProperties instance.
*/
@Override
protected Map<String, Object> extractStandardHeaders(MessageProperties amqpMessageProperties) {
Map<String, Object> headers = new HashMap<>();
protected Map<String, @Nullable Object> extractStandardHeaders(MessageProperties amqpMessageProperties) {
Map<String, @Nullable Object> headers = new HashMap<>();
try {
JavaUtils.INSTANCE
.acceptIfNotNull(AmqpHeaders.APP_ID, amqpMessageProperties.getAppId(), headers::put)
Expand Down Expand Up @@ -326,13 +327,13 @@ else if (contentType instanceof String) {
}

@Override
public Map<String, Object> toHeadersFromRequest(MessageProperties source) {
Map<String, Object> headersFromRequest = super.toHeadersFromRequest(source);
public Map<String, @Nullable Object> toHeadersFromRequest(MessageProperties source) {
Map<String, @Nullable Object> headersFromRequest = super.toHeadersFromRequest(source);
addConsumerMetadata(source, headersFromRequest);
return headersFromRequest;
}

private void addConsumerMetadata(MessageProperties messageProperties, Map<String, Object> headers) {
private void addConsumerMetadata(MessageProperties messageProperties, Map<String, @Nullable Object> headers) {
String consumerTag = messageProperties.getConsumerTag();
if (consumerTag != null) {
headers.put(AmqpHeaders.CONSUMER_TAG, consumerTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @author Stephane Nicoll
* @author Gary Russell
* @author Artem Bilan
* @author Glenn Renfro
*
* @since 2.1
*/
Expand Down Expand Up @@ -87,7 +88,7 @@ public abstract class AbstractHeaderMapper<T> implements RequestReplyHeaderMappe

private HeaderMatcher replyHeaderMatcher;

private ClassLoader classLoader = ClassUtils.getDefaultClassLoader();
private @Nullable ClassLoader classLoader = ClassUtils.getDefaultClassLoader();

/**
* Create a new instance.
Expand All @@ -113,7 +114,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}

protected ClassLoader getClassLoader() {
protected @Nullable ClassLoader getClassLoader() {
return this.classLoader;
}

Expand Down Expand Up @@ -204,12 +205,12 @@ public void fromHeadersToReply(MessageHeaders headers, T target) {
}

@Override
public Map<String, Object> toHeadersFromRequest(T source) {
public Map<String, @Nullable Object> toHeadersFromRequest(T source) {
return toHeaders(source, this.requestHeaderMatcher);
}

@Override
public Map<String, Object> toHeadersFromReply(T source) {
public Map<String, @Nullable Object> toHeadersFromReply(T source) {
return toHeaders(source, this.replyHeaderMatcher);
}

Expand Down Expand Up @@ -264,18 +265,19 @@ private boolean isMessageChannel(String headerName, Object headerValue) {
* Map headers from a source instance to the {@link MessageHeaders} of
* a {@link org.springframework.messaging.Message}.
*/
private Map<String, Object> toHeaders(T source, HeaderMatcher headerMatcher) {
Map<String, Object> headers = new HashMap<>();
Map<String, Object> standardHeaders = extractStandardHeaders(source);
private Map<String, @Nullable Object> toHeaders(T source, HeaderMatcher headerMatcher) {
Map<String, @Nullable Object> headers = new HashMap<>();
Map<String, @Nullable Object> standardHeaders = extractStandardHeaders(source);
copyHeaders(standardHeaders, headers, headerMatcher);
Map<String, Object> userDefinedHeaders = extractUserDefinedHeaders(source);
Map<String, @Nullable Object> userDefinedHeaders = extractUserDefinedHeaders(source);
copyHeaders(userDefinedHeaders, headers, headerMatcher);
return headers;
}

private void copyHeaders(Map<String, Object> source, Map<String, Object> target, HeaderMatcher headerMatcher) {
private void copyHeaders(Map<String, @Nullable Object> source, Map<String, @Nullable Object> target,
HeaderMatcher headerMatcher) {
if (!CollectionUtils.isEmpty(source)) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
for (Map.Entry<String, @Nullable Object> entry : source.entrySet()) {
try {
String headerName = createTargetPropertyName(entry.getKey(), false);
if (shouldMapHeader(headerName, headerMatcher)) {
Expand Down Expand Up @@ -365,7 +367,7 @@ protected Collection<String> getTransientHeaderNames() {
* @param source the source object to extract standard headers.
* @return the map of headers to be mapped.
*/
protected abstract Map<String, Object> extractStandardHeaders(T source);
protected abstract Map<String, @Nullable Object> extractStandardHeaders(T source);

/**
* Extract the user-defined headers from the specified source.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Provides classes related to mapping to/from message headers.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mapping;
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Contract;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
Expand All @@ -32,6 +34,7 @@
*
* @author Artem Bilan
* @author Gary Russell
* @author Glenn Renfro
*
* @since 3.0
*/
Expand Down Expand Up @@ -67,18 +70,18 @@ private JsonHeaders() {
* @return the {@link ResolvableType} based on provided class components
* @since 5.2.4
*/
public static ResolvableType buildResolvableType(ClassLoader classLoader, Object targetClassValue,
public static ResolvableType buildResolvableType(@Nullable ClassLoader classLoader, Object targetClassValue,
@Nullable Object contentClassValue, @Nullable Object keyClassValue) {

Class<?> targetClass = getClassForValue(classLoader, targetClassValue);
Class<?> keyClass = getClassForValue(classLoader, keyClassValue);
Class<?> contentClass = getClassForValue(classLoader, contentClassValue);

Assert.notNull(targetClass, "targetClass must not be null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you fix getClassForValue() with the @Contract, this is not necessary.

return buildResolvableType(targetClass, contentClass, keyClass);
}

@Nullable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move this next to the return type.

private static Class<?> getClassForValue(ClassLoader classLoader, @Nullable Object classValue) {
private static Class<?> getClassForValue(@Nullable ClassLoader classLoader, @Nullable Object classValue) {
if (classValue instanceof Class<?>) {
return (Class<?>) classValue;
}
Expand All @@ -103,9 +106,9 @@ else if (classValue != null) {
* @return the {@link ResolvableType} based on provided class components
* @since 5.2.4
*/
@Contract("_, !null, _ -> !null; _, _, !null -> !null")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong.
The method does not return null at all.
See getClassForValue().
That's where the @Contract has to be.

public static ResolvableType buildResolvableType(Class<?> targetClass, @Nullable Class<?> contentClass,
@Nullable Class<?> keyClass) {

if (keyClass != null) {
return TypeDescriptor
.map(targetClass,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Support classes for mapping.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mapping.support;
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Artem Bilan
* @author Gary Russell
* @author Jooyoung Pyoung
* @author Glenn Renfro
*
* @since 2.0
*/
Expand All @@ -74,10 +75,10 @@ public DefaultSoapHeaderMapper() {
}

@Override
protected Map<String, Object> extractStandardHeaders(SoapMessage source) {
protected Map<String, @Nullable Object> extractStandardHeaders(SoapMessage source) {
final String soapAction = source.getSoapAction();
if (StringUtils.hasText(soapAction)) {
Map<String, Object> headers = new HashMap<>(1);
Map<String, @Nullable Object> headers = new HashMap<>(1);
headers.put(WebServiceHeaders.SOAP_ACTION, soapAction);
return headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @author Florian Schmaus
* @author Stephane Nicoll
* @author Artem Bilan
* @author Glenn Renfro
*
* @since 2.1
*/
Expand All @@ -61,8 +62,8 @@ public DefaultXmppHeaderMapper() {
}

@Override
protected Map<String, Object> extractStandardHeaders(MessageBuilder source) {
Map<String, Object> headers = new HashMap<>();
protected Map<String, @Nullable Object> extractStandardHeaders(MessageBuilder source) {
Map<String, @Nullable Object> headers = new HashMap<>();
Jid from = source.getFrom();
if (from != null) {
headers.put(XmppHeaders.FROM, from.toString());
Expand Down
Loading