Skip to content

MimeMessage.setFrom(null) fails instead of removing the header #456

@angelusmetal

Description

@angelusmetal

Even though the method's java doc states:

Set the RFC 822 "From" header field. Any existing values are replaced with the given address.
If address is null, this header is removed.

The change in ac77368 is deferring the null check to remove the header to setAddressHeader(); however it is providing an array with a single null element, which is not what the code expects.

setFrom(InternetAddress) fails with the following stacktrace:

java.lang.NullPointerException
	at javax.mail.internet.InternetAddress.toUnicodeString(InternetAddress.java:534)
	at javax.mail.internet.MimeMessage.setAddressHeader(MimeMessage.java:731)
	at javax.mail.internet.MimeMessage.setFrom(MimeMessage.java:382)

setFrom(String) fails with the following stacktrace:

java.lang.NullPointerException
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:769)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:728)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:705)
	at javax.mail.internet.MimeMessage.setFrom(MimeMessage.java:400)

Either the if/else check on each setXxx() method should be reinstated, or setAddressHeader() should expect an array with a single null value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions