diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java index de1c9085ea2..e09671aa564 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java @@ -40,6 +40,7 @@ import jakarta.mail.Store; import jakarta.mail.URLName; import jakarta.mail.internet.MimeMessage; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.expression.Expression; @@ -79,7 +80,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl */ public static final String DEFAULT_SI_USER_FLAG = "spring-integration-mail-adapter"; - private final URLName url; + private final @Nullable URLName url; private final ReentrantReadWriteLock folderLock = new ReentrantReadWriteLock(); @@ -87,11 +88,11 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl private final Lock folderWriteLock = this.folderLock.writeLock(); - private String protocol; + private @Nullable String protocol; private int maxFetchSize = -1; - private Session session; + private @Nullable Session session; private boolean shouldDeleteMessages; @@ -99,13 +100,14 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl private Properties javaMailProperties = new Properties(); - private Authenticator javaMailAuthenticator; + private @Nullable Authenticator javaMailAuthenticator; + @SuppressWarnings("NullAway.Init") private StandardEvaluationContext evaluationContext; - private Expression selectorExpression; + private @Nullable Expression selectorExpression; - private HeaderMapper headerMapper; + private @Nullable HeaderMapper headerMapper; private String userFlag = DEFAULT_SI_USER_FLAG; @@ -117,9 +119,9 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl private boolean flaggedAsFallback = true; - private volatile Store store; + private volatile @Nullable Store store; - private volatile Folder folder; + private volatile @Nullable Folder folder; public AbstractMailReceiver() { this.url = null; @@ -130,7 +132,7 @@ public AbstractMailReceiver(URLName urlName) { this.url = urlName; } - public AbstractMailReceiver(String url) { + public AbstractMailReceiver(@Nullable String url) { if (url != null) { this.url = new URLName(url); } @@ -139,7 +141,7 @@ public AbstractMailReceiver(String url) { } } - public void setSelectorExpression(Expression selectorExpression) { + public void setSelectorExpression(@Nullable Expression selectorExpression) { this.selectorExpression = selectorExpression; } @@ -306,7 +308,7 @@ public void setFlaggedAsFallback(boolean flaggedAsFallback) { this.flaggedAsFallback = flaggedAsFallback; } - protected Folder getFolder() { + protected @Nullable Folder getFolder() { return this.folder; } @@ -334,6 +336,7 @@ private void openSession() { private void connectStoreIfNecessary() throws MessagingException { if (this.store == null) { + Assert.state(this.session != null, "'session' should not be null"); if (this.url != null) { this.store = this.session.getStore(this.url); } @@ -345,7 +348,8 @@ else if (this.protocol != null) { } } if (!this.store.isConnected()) { - this.logger.debug(() -> "connecting to store [" + this.store.getURLName() + "]"); + URLName urlName = this.store.getURLName(); + this.logger.debug(() -> "connecting to store [" + urlName + "]"); this.store.connect(); } } @@ -360,7 +364,8 @@ protected void openFolder() throws MessagingException { connectStoreIfNecessary(); } if (this.folder == null || !this.folder.exists()) { - throw new IllegalStateException("no such folder [" + this.url.getFile() + "]"); + String file = this.url != null ? this.url.getFile() : ""; + throw new IllegalStateException("no such folder [" + file + "]"); } if (this.folder.isOpen()) { return; @@ -371,6 +376,7 @@ protected void openFolder() throws MessagingException { } private Folder obtainFolderInstance() throws MessagingException { + Assert.state(this.store != null, "'store' should not be null"); if (this.url == null) { return this.store.getDefaultFolder(); } @@ -422,7 +428,9 @@ protected void closeFolder() { } private MimeMessage[] searchAndFilterMessages() throws MessagingException { - this.logger.debug(() -> "attempting to receive mail from folder [" + this.folder.getFullName() + "]"); + Assert.state(this.folder != null, "'folder' should not be null"); + String fullName = this.folder.getFullName(); + this.logger.debug(() -> "attempting to receive mail from folder [" + fullName + "]"); Message[] messagesToProcess; Message[] messages = searchForNewMessages(); if (this.maxFetchSize > 0 && messages.length > this.maxFetchSize) { @@ -549,7 +557,9 @@ private void setMessageFlagsAndMaybeDeleteMessages(Message[] messages) throws Me private void setMessageFlags(Message[] filteredMessages) throws MessagingException { boolean recentFlagSupported = false; - Flags flags = getFolder().getPermanentFlags(); + Folder folder = getFolder(); + Assert.state(folder != null, "'folder' should not be null"); + Flags flags = folder.getPermanentFlags(); if (flags != null) { recentFlagSupported = flags.contains(Flags.Flag.RECENT); @@ -612,6 +622,7 @@ protected void fetchMessages(Message[] messages) throws MessagingException { contentsProfile.add(FetchProfile.Item.ENVELOPE); contentsProfile.add(FetchProfile.Item.CONTENT_INFO); contentsProfile.add(FetchProfile.Item.FLAGS); + Assert.state(this.folder != null, "'folder' should not be null"); this.folder.fetch(messages, contentsProfile); } @@ -658,10 +669,12 @@ protected void onInit() { @Override public String toString() { - return this.url.toString(); + String urlName = this.store != null && this.store.getURLName() != null + ? this.store.getURLName().toString() : ""; + return this.url != null ? this.url.toString() : urlName; } - Store getStore() { + @Nullable Store getStore() { return this.store; } @@ -678,7 +691,7 @@ private final class IntegrationMimeMessage extends MimeMessage { private final MimeMessage source; - private final Object content; + private final @Nullable Object content; IntegrationMimeMessage(MimeMessage source) throws MessagingException { super(source); @@ -700,7 +713,7 @@ private final class IntegrationMimeMessage extends MimeMessage { } @Override - public Folder getFolder() { + public @Nullable Folder getFolder() { if (!AbstractMailReceiver.this.autoCloseFolder) { return AbstractMailReceiver.this.folder; } @@ -731,7 +744,7 @@ public int getLineCount() throws MessagingException { } @Override - public Object getContent() throws IOException, MessagingException { + public @Nullable Object getContent() throws IOException, MessagingException { if (AbstractMailReceiver.this.simpleContent) { return super.getContent(); } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java index b86057eed53..b959ebc8737 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -24,6 +24,7 @@ import jakarta.mail.Folder; import jakarta.mail.Message; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanClassLoaderAware; @@ -35,7 +36,6 @@ import org.springframework.integration.transaction.IntegrationResourceHolder; import org.springframework.integration.transaction.IntegrationResourceHolderSynchronization; import org.springframework.integration.transaction.TransactionSynchronizationFactory; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessagingException; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -62,18 +62,22 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport implements Be private final ImapMailReceiver mailReceiver; + @SuppressWarnings("NullAway.Init") private Executor taskExecutor; - private TransactionSynchronizationFactory transactionSynchronizationFactory; + private @Nullable TransactionSynchronizationFactory transactionSynchronizationFactory; + @SuppressWarnings("NullAway.Init") private ClassLoader classLoader; + @SuppressWarnings("NullAway.Init") private ApplicationEventPublisher applicationEventPublisher; private boolean shouldReconnectAutomatically = true; - private List adviceChain; + private @Nullable List adviceChain; + @SuppressWarnings("NullAway.Init") private Consumer messageSender; private long reconnectDelay = DEFAULT_RECONNECT_DELAY; // milliseconds @@ -252,8 +256,8 @@ private void delayNextIdleCall() { } } - @Nullable - private static jakarta.mail.MessagingException getJakartaMailMessagingExceptionFromCause(Throwable cause) { + private static jakarta.mail.@Nullable MessagingException getJakartaMailMessagingExceptionFromCause( + @Nullable Throwable cause) { if (cause == null) { return null; } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java index b7d145ac330..c2d8aec465a 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java @@ -33,6 +33,7 @@ import jakarta.mail.search.NotTerm; import jakarta.mail.search.SearchTerm; import org.eclipse.angus.mail.imap.IMAPFolder; +import org.jspecify.annotations.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -67,11 +68,12 @@ public class ImapMailReceiver extends AbstractMailReceiver { private long cancelIdleInterval = DEFAULT_CANCEL_IDLE_INTERVAL; + @SuppressWarnings("NullAway.Init") private TaskScheduler scheduler; private boolean isInternalScheduler; - private volatile ScheduledFuture pingTask; + private volatile @Nullable ScheduledFuture pingTask; @SuppressWarnings("this-escape") public ImapMailReceiver() { @@ -79,7 +81,7 @@ public ImapMailReceiver() { } @SuppressWarnings("this-escape") - public ImapMailReceiver(String url) { + public ImapMailReceiver(@Nullable String url) { super(url); if (url != null) { Assert.isTrue(url.toLowerCase(Locale.ROOT).startsWith(PROTOCOL), @@ -212,6 +214,7 @@ else if (!folder.getPermanentFlags().contains(Flags.Flag.RECENT) && searchForNew @Override protected Message[] searchForNewMessages() throws MessagingException { Folder folderToUse = getFolder(); + Assert.state(folderToUse != null, "'folderToUse' should not be null"); Flags supportedFlags = folderToUse.getPermanentFlags(); SearchTerm searchTerm = compileSearchTerms(supportedFlags); if (folderToUse.isOpen()) { @@ -238,8 +241,10 @@ private Message[] nullSafeMessages(Message[] messageArray) { } } - private SearchTerm compileSearchTerms(Flags supportedFlags) { - return this.searchTermStrategy.generateSearchTerm(supportedFlags, this.getFolder()); + private @Nullable SearchTerm compileSearchTerms(Flags supportedFlags) { + Folder folderToUse = this.getFolder(); + Assert.state(folderToUse != null, "'folderToUse' should not be null"); + return this.searchTermStrategy.generateSearchTerm(supportedFlags, folderToUse); } @Override @@ -277,7 +282,7 @@ private class DefaultSearchTermStrategy implements SearchTermStrategy { } @Override - public SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) { + public @Nullable SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) { SearchTerm searchTerm = null; boolean recentFlagSupported = false; if (supportedFlags != null) { @@ -320,7 +325,7 @@ public SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) { return searchTerm; } - private SearchTerm applyTermsWhenNoRecentFlag(Folder folder, SearchTerm searchTerm) { + private SearchTerm applyTermsWhenNoRecentFlag(Folder folder, @Nullable SearchTerm searchTerm) { NotTerm notFlagged; if (folder.getPermanentFlags().contains(Flag.USER)) { logger.debug(() -> "This email server does not support RECENT flag, but it does support " + diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceiver.java index df7f14c0b8e..438a64db4e5 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceiver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 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.mail; +import org.jspecify.annotations.Nullable; + /** * Strategy interface for receiving mail {@link jakarta.mail.Message Messages}. * @@ -25,6 +27,6 @@ */ public interface MailReceiver { - Object[] receive() throws jakarta.mail.MessagingException; + Object @Nullable [] receive() throws jakarta.mail.MessagingException; } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java index f1da2e4c88a..d5c74c779d9 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -20,6 +20,8 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import org.jspecify.annotations.Nullable; + import org.springframework.core.log.LogMessage; import org.springframework.integration.endpoint.AbstractMessageSource; import org.springframework.messaging.MessagingException; @@ -54,7 +56,7 @@ public String getComponentType() { } @Override - protected Object doReceive() { + protected @Nullable Object doReceive() { try { Object mailMessage = this.mailQueue.poll(); if (mailMessage == null) { diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailSendingMessageHandler.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailSendingMessageHandler.java index 755c347a6eb..7ec87010031 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailSendingMessageHandler.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailSendingMessageHandler.java @@ -16,8 +16,12 @@ package org.springframework.integration.mail; +import java.util.Arrays; +import java.util.Objects; + import jakarta.mail.MessagingException; import jakarta.mail.internet.MimeMessage; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.ByteArrayResource; import org.springframework.integration.handler.AbstractMessageHandler; @@ -190,12 +194,14 @@ private void applyHeadersToMailMessage(MailMessage mailMessage, MessageHeaders h } } - private String[] retrieveHeaderValueAsStringArray(MessageHeaders headers, String key) { + private String @Nullable [] retrieveHeaderValueAsStringArray(MessageHeaders headers, String key) { Object value = headers.get(key); String[] returnedHeaders = null; if (value != null) { - if (value instanceof String[]) { - returnedHeaders = (String[]) value; + if (value instanceof String[] strArr) { + returnedHeaders = Arrays.stream(strArr) + .filter(Objects::nonNull) + .toArray(String[]::new); } else if (value instanceof String) { returnedHeaders = StringUtils.commaDelimitedListToStringArray((String) value); diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailTransportUtils.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailTransportUtils.java index 4a0ee5e3b6c..390f6e51c72 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailTransportUtils.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailTransportUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2024 the original author or authors. + * Copyright 2007-2025 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. @@ -22,6 +22,7 @@ import jakarta.mail.URLName; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.util.StringUtils; @@ -44,7 +45,7 @@ public abstract class MailTransportUtils { * @see jakarta.mail.Transport * @see jakarta.mail.Store */ - public static void closeService(Service service) { + public static void closeService(@Nullable Service service) { if (service != null) { try { service.close(); @@ -61,7 +62,7 @@ public static void closeService(Service service) { * @param folder the JavaMail Folder to close (may be null) * @param expunge whether all deleted messages should be expunged from the folder */ - public static void closeFolder(Folder folder, boolean expunge) { + public static void closeFolder(@Nullable Folder folder, boolean expunge) { if (folder != null && folder.isOpen()) { try { folder.close(expunge); diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/Pop3MailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/Pop3MailReceiver.java index 2318b7cb459..2e4420d95bd 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/Pop3MailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/Pop3MailReceiver.java @@ -21,6 +21,7 @@ import jakarta.mail.MessagingException; import jakarta.mail.URLName; import jakarta.mail.internet.MimeMessage; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; @@ -41,7 +42,7 @@ public Pop3MailReceiver() { } @SuppressWarnings("this-escape") - public Pop3MailReceiver(String url) { + public Pop3MailReceiver(@Nullable String url) { super(url); if (url != null) { Assert.isTrue(url.startsWith(PROTOCOL), "url must start with 'pop3'"); @@ -63,6 +64,7 @@ public Pop3MailReceiver(String host, int port, String username, String password) @Override protected Message[] searchForNewMessages() throws MessagingException { Folder folderToUse = getFolder(); + Assert.state(folderToUse != null, "'folderToUse' should not be null"); int messageCount = folderToUse.getMessageCount(); if (messageCount == 0) { return new Message[0]; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java index 6f294834801..ec15ef37a7a 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 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. @@ -19,6 +19,7 @@ import jakarta.mail.Flags; import jakarta.mail.Folder; import jakarta.mail.search.SearchTerm; +import org.jspecify.annotations.Nullable; /** * Strategy to be used to generate a {@link SearchTerm}. @@ -38,6 +39,6 @@ public interface SearchTermStrategy { * @param folder The folder. * @return The search term. */ - SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder); + @Nullable SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder); } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java index 11b029b5747..c10146cc90c 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -23,6 +23,7 @@ import jakarta.mail.Session; import jakarta.mail.URLName; import jakarta.mail.internet.MimeMessage; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.DisposableBean; @@ -34,7 +35,6 @@ import org.springframework.integration.mail.Pop3MailReceiver; import org.springframework.integration.mail.SearchTermStrategy; import org.springframework.integration.mapping.HeaderMapper; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -48,41 +48,42 @@ */ public class MailReceiverFactoryBean extends AbstractFactoryBean { - private String storeUri; + private @Nullable String storeUri; - private String protocol; + private @Nullable String protocol; - private Session session; + private @Nullable Session session; + @SuppressWarnings("NullAway.Init") private MailReceiver receiver; - private Properties javaMailProperties; + private @Nullable Properties javaMailProperties; - private Authenticator authenticator; + private @Nullable Authenticator authenticator; /** * Indicates whether retrieved messages should be deleted from the server. * This value will be null unless explicitly configured. */ - private Boolean shouldDeleteMessages = null; + private @Nullable Boolean shouldDeleteMessages = null; - private Boolean shouldMarkMessagesAsRead = null; + private @Nullable Boolean shouldMarkMessagesAsRead = null; private int maxFetchSize = 1; - private Expression selectorExpression; + private @Nullable Expression selectorExpression; - private SearchTermStrategy searchTermStrategy; + private @Nullable SearchTermStrategy searchTermStrategy; - private String userFlag; + private @Nullable String userFlag; - private HeaderMapper headerMapper; + private @Nullable HeaderMapper headerMapper; - private Boolean embeddedPartsAsBytes; + private @Nullable Boolean embeddedPartsAsBytes; - private Boolean simpleContent; + private @Nullable Boolean simpleContent; - private Boolean autoCloseFolder; + private @Nullable Boolean autoCloseFolder; public void setStoreUri(@Nullable String storeUri) { this.storeUri = storeUri; @@ -163,6 +164,7 @@ public Class getObjectType() { private MailReceiver createReceiver() { // NOSONAR verifyProtocol(); + Assert.state(this.protocol != null, "'protocol' should not be null "); boolean isPop3 = this.protocol.toLowerCase(Locale.ROOT).startsWith("pop3"); boolean isImap = this.protocol.toLowerCase(Locale.ROOT).startsWith("imap"); Assert.isTrue(isPop3 || isImap, "the store URI must begin with 'pop3' or 'imap'"); @@ -203,7 +205,7 @@ private MailReceiver createReceiver() { // NOSONAR } } else { - ((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(this.shouldMarkMessagesAsRead); + ((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(isShouldMarkMessagesAsRead()); } BeanFactory beanFactory = getBeanFactory(); if (beanFactory != null) { diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/package-info.java index e425b6f6f39..ad55b5a96ba 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes for configuration - parsers, namespace handlers. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail.config; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/Mail.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/Mail.java index 350577db20d..f85965e3a11 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/Mail.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/Mail.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2024 the original author or authors. + * Copyright 2014-2025 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,11 +16,12 @@ package org.springframework.integration.mail.dsl; +import org.jspecify.annotations.Nullable; + import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.integration.mail.MailSendingMessageHandler; import org.springframework.integration.mail.Pop3MailReceiver; import org.springframework.integration.mail.transformer.MailToStringTransformer; -import org.springframework.lang.Nullable; import org.springframework.mail.MailSender; /** diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/MailSendingMessageHandlerSpec.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/MailSendingMessageHandlerSpec.java index 58f6a2d7df6..4ec6e1ff5ef 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/MailSendingMessageHandlerSpec.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/MailSendingMessageHandlerSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2025 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. @@ -20,11 +20,11 @@ import java.util.function.Consumer; import jakarta.activation.FileTypeMap; +import org.jspecify.annotations.Nullable; import org.springframework.integration.dsl.MessageHandlerSpec; import org.springframework.integration.mail.MailSendingMessageHandler; import org.springframework.integration.support.PropertiesBuilder; -import org.springframework.lang.Nullable; import org.springframework.mail.javamail.JavaMailSenderImpl; /** diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/package-info.java index d2e39f7120f..6215a49faec 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/package-info.java @@ -1,6 +1,5 @@ /** * Provides Mail Components for the Java DSL. */ -@org.springframework.lang.NonNullApi -@org.springframework.lang.NonNullFields +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail.dsl; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/event/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/event/package-info.java index 0f7c64b380d..01c1af14d35 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/event/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/event/package-info.java @@ -1,4 +1,5 @@ /** * Events generated by the mail module */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail.event; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/package-info.java index 7e4b1b0e8ed..85463754963 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/package-info.java @@ -1,4 +1,5 @@ /** * Base package for Mail support. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/package-info.java index 30c28447277..2786b2e43ac 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes to support email. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail.support; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java index b2ecf565dad..135bed3433b 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -18,6 +18,8 @@ import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.integration.mail.support.MailUtils; @@ -41,7 +43,7 @@ */ public abstract class AbstractMailMessageTransformer implements Transformer, BeanFactoryAware { - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); @@ -71,9 +73,6 @@ public Message transform(Message message) { } AbstractIntegrationMessageBuilder builder; builder = doTransform(mailMessage); - if (builder == null) { - throw new MessageTransformationException(message, "failed to transform mail message"); - } return builder.copyHeaders(extractHeaderMapFromMailMessage(mailMessage)).build(); } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/package-info.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/package-info.java index ec8b5ff597b..9fa5e689e71 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/package-info.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes related to transforming mail messages. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.mail.transformer;