Java mail mimeutility. Quote function throws NULL pointer exception.

Source: Internet
Author: User

Today, the Java mail mimeutility. Quote function throws a null pointer exception. Looking for this problem does waste a lot of time: Look at the stack information, look at the source code, debug. Then finally found the cause of the problem:

In the email, the mimebody contains the following line:

 
Content-Type: Application/octet-stream; name = ""

This sentence is quite amazing. It throws NPE from javamail. But is there a problem with the javamail library, or is this email not compliant with RFC specifications?

As a result, I found the RFC document, Chapter 2045 in RFC 5.1, and found the following content:

 
Value: = token/quoted-stringtoken: = 1 * <Any (US-ASCII) Char character t space, CTLs, or tspecials> tspecials: = "("/") "/" <"/"> "/"@"/","/";"/": "/" \ "/<"> "/"/"["/"]"/"? "/" = "; Must be in quoted-string,; To use within parameter values

This is a syntax definition. The Lexical definition of the Content-Type header field is clearly written and should not be empty. So javamail finds that it is appropriate to throw an exception if it is null. Therefore, the error lies in the sender. Here, we can see how to discard the mail that cannot be well resolved. Then, report the bug to the sender. So software development... you still need to check the RFC from time to time...

In addition, the above problem is that the NULL pointer exception is thrown when the P. getcontent (); p. getdatahandler () or P. getinputstream () method is called after the multipart P is obtained.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.