2012-11-06 11 views
6

Próbuję pobrać wiadomości przy użyciu JavaMail 1.4.5 z konta IMAP i otrzymuję wyjątek wskaźnika pustego w metodzie BODYSTRUCTURE.parseParameters.JavaMail: zerowanie wskaźnika w BODYSTRUCTURE.parseParameters. Czy to błąd?

Patrząc kod parseParameters uważam, że ta linia

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

Problemem jest to, że metoda zestaw próbuje zadzwonić .toLowerCase() do wartości zerowej !!!

Odpowiedź stara się analizować to:

* 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)) 

i umożliwiając debugowanie, mam takie komunikaty:

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 

a następnie 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 

Dziękuję wszystkim, którzy mogą mi pomóc!

Odpowiedz

8

Prawdopodobnie masz mieszankę klas JavaMail z dwóch różnych wersji JavaMail. Sprawdź ścieżkę klas dla innych instancji klas javax.mail. *, Być może w pliku j2ee.jar lub javaee.jar.

10

W końcu odkryłem przyczynę problemu.

Dołączam Apache Cxf do mojego projektu.

Cxf zawiera odniesienie do geronimo-javamail_1.4_spec, które nadpisuje niektóre klasy javamail.

Z wyjątkiem odniesienia do geronimo, wszystko działa poprawnie!

+3

Spędziłem bardzo długo dzień szuka właśnie tego rozwiązania.Kiedy znalazłem twój post, zajęło mi to tylko pół godziny. Dziękuję bardzo za poświęcenie czasu, aby umieścić tutaj swoje pytanie i odpowiedź. To zrobiło dla mnie ogromną różnicę. – Spina

0

Miałem podobny (być może ten sam) problem.

Problem był związany z błędem serwera poczty opisanym w tym FAQ Oracle here.

Rozwiązaniem jest:

  • naprawić błąd w serwerze IMAP
  • LUB użyć obejścia opisanego w 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. 
    

lub

// 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. 

Znalazłem ten dzięki tej forach Oracle thread

0

Dzięki za sugestię daj mi tego problemu

dodam poniżej zależność w moim projekcie i wszystko działa poprawnie

<dependency> 
    <groupId>org.apache.cxf</groupId> 
    <artifactId>cxf-api</artifactId> 
    <version>2.1.3</version> 
    <type>jar</type> 
</dependency>