- Notifications
You must be signed in to change notification settings - Fork38.6k
Closed
Milestone
Description
Affects: spring-context-support-6.1.12
I'm creating a mail using MimeMessageHelper. I want to add inline file using ByteArrayResource.
The function used is :
publicvoidaddInline(StringcontentId,Resourceresource)throwsMessagingException {Assert.notNull(resource,"Resource must not be null");StringcontentType =getFileTypeMap().getContentType(resource.getFilename());addInline(contentId,resource,contentType);}
The problem is that org.springframework.core.io.ByteArrayResource extends org.springframework.core.io.AbstractResource which implements getFilename() returning null
/** * This implementation always returns {@code null}, * assuming that this resource type does not have a filename. */@Override@NullablepublicStringgetFilename() {returnnull;}
So
StringcontentType =getFileTypeMap().getContentType(resource.getFilename());
throw a java.lang.NullPointerException because jakarta.activation.MimetypesFileTypeMap.getContentType(String filename) code start with :
publicsynchronizedStringgetContentType(Stringfilename) {intdot_pos =filename.lastIndexOf(".");// period index
(jakarta.activation-api.2.1.3)
The thrown trace is
Caused by: java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(String)" because "filename" is nullat jakarta.activation.MimetypesFileTypeMap.getContentType(MimetypesFileTypeMap.java:361)at org.springframework.mail.javamail.ConfigurableMimeFileTypeMap.getContentType(ConfigurableMimeFileTypeMap.java:180)