2012-11-06 33 views
6

Tôi đang cố tìm nạp thư bằng JavaMail 1.4.5 từ tài khoản IMAP và tôi nhận được ngoại lệ con trỏ null trong phương thức BODYSTRUCTURE.parseParameters.JavaMail: Null pointer exeception trong BODYSTRUCTURE.parseParameters. Nó là một lỗi?

Nhìn mã parseParameters, tôi thấy dòng này

list.set(null, "DONE"); // XXX - hack 

Vấn đề là phương thức thiết lập cố gắng gọi .toLowerCase() tới giá trị null !!!

Câu trả lời nó đang cố gắng phân tích cú pháp là:

* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 55 4 NIL NIL NIL NIL)(("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "7BIT" 410 10 NIL NIL NIL NIL)("IMAGE" "JPEG" ("NAME" "image.jpg") "<[email protected]>" NIL "BASE64" 536628 NIL ("inline" ("FILENAME" "image.jpg")) NIL NIL) "RELATED" ("TYPE" "text/html" "BOUNDARY" "Apple-Mail=_56FA3EC6-FB02-4882-A1C5-487652E3B4E5") NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "Apple-Mail=_CB164992-2501-4351-94D1-61CE7C8D90DC") NIL NIL NIL)) 

và, cho phép gỡ lỗi, tôi nhận được những thông điệp:

DEBUG IMAP: parsing BODYSTRUCTURE 
DEBUG IMAP: msgno 1 
DEBUG IMAP: parsing multipart 
DEBUG IMAP: parsing BODYSTRUCTURE 
DEBUG IMAP: msgno 1 
DEBUG IMAP: single part 
DEBUG IMAP: type TEXT 
DEBUG IMAP: subtype PLAIN 
DEBUG IMAP: parameter name CHARSET 
DEBUG IMAP: parameter value us-ascii 

và sau đó là NullPointerException

Exception in thread "main" java.lang.NullPointerException 
at javax.mail.internet.ParameterList.set(ParameterList.java:165) 
at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:404) 
at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:224) 
at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:109) 
at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:158) 
at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:67) 
at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:136) 
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:270) 
at com.sun.mail.iap.Protocol.command(Protocol.java:313) 
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1529) 
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1521) 
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1221) 
at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1307) 
at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:623) 
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:927 

Nhờ bất cứ ai có thể giúp tôi!

Trả lời

8

Bạn có thể đã kết hợp các lớp JavaMail từ hai phiên bản JavaMail khác nhau. Kiểm tra classpath của bạn cho các trường hợp khác của các lớp javax.mail. *, Có thể trong một j2ee.jar hoặc javaee.jar.

10

Cuối cùng tôi đã phát hiện ra nguyên nhân của sự cố.

Tôi đang bao gồm Apache Cxf trong dự án của mình.

Cxf bao gồm tham chiếu đến geronimo-javamail_1.4_spec ghi đè một số lớp javamail.

Không bao gồm tham chiếu đến geronimo, mọi thứ hoạt động chính xác!

+3

Tôi đã dành rất dài ngày chỉ tìm kiếm giải pháp này.Một khi tôi tìm thấy bài viết của bạn nó chỉ mất một nửa giờ để có được bản thân mình đi. Cảm ơn bạn rất nhiều vì đã dành thời gian để đặt câu hỏi của bạn và trả lời ở đây. Nó tạo ra một sự khác biệt rất lớn đối với tôi. – Spina

0

Tôi có vấn đề tương tự (có thể giống nhau).

Sự cố đã được kết nối với lỗi máy chủ thư được mô tả trong Câu hỏi thường gặp về Oracle này here.

Giải pháp là:

  • sửa chữa các lỗi trong máy chủ IMAP của bạn
  • HOẶC sử dụng workaround được mô tả trong Oracle FAQ

    // Get the message object from the folder in the 
    // usual way, for example: 
    MimeMessage msg = (MimeMessage)folder.getMessage(n); 
    
    // Use the MimeMessage copy constructor to make a copy 
    // of the entire message, which will fetch the entire 
    // message from the server and parse it on the client: 
    MimeMessage cmsg = new MimeMessage(msg); 
    
    // The cmsg object is disconnected from the server so 
    // setFlags will have no effect (for example). Use 
    // the original msg object for such operations. Use 
    // the cmsg object to access the content of the message. 
    

hoặc

// Get the message object from the folder in the 
// usual way, for example: 
MimeMessage msg = (MimeMessage)folder.getMessage(n); 

// Copy the message by writing into an byte array and 
// creating a new MimeMessage object based on the contents 
// of the byte array: 
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
msg.writeTo(bos); 
bos.close(); 
SharedByteArrayInputStream bis = 
     new SharedByteArrayInputStream(bos.toByteArray()); 
MimeMessage cmsg = new MimeMessage(session, bis); 
bis.close(); 

// The cmsg object is disconnected from the server so 
// setFlags will have no effect (for example). Use 
// the original msg object for such operations. Use 
// the cmsg object to access the content of the message. 

Tôi đã thấy điều này nhờ vào các diễn đàn Oracle này thread

0

Cám ơn cho tôi gợi ý cho vấn đề này

tôi Thêm dưới đây phụ thuộc vào dự án của tôi và tất cả mọi thứ hoạt động bình thường

<dependency> 
    <groupId>org.apache.cxf</groupId> 
    <artifactId>cxf-api</artifactId> 
    <version>2.1.3</version> 
    <type>jar</type> 
</dependency> 
Các vấn đề liên quan