2012-11-06 10 views
6

Sto cercando di recuperare i messaggi utilizzando JavaMail 1.4.5 da un account IMAP e ottengo un'eccezione di puntatore nullo nel metodo BODYSTRUCTURE.parseParameters.JavaMail: Esecuzione puntatore nullo in BODYSTRUCTURE.parseParameters. E 'un errore?

Guardando il codice parseParameters, trovo questa linea

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

Il problema è che il metodo set tenta di chiamare .tolowercase() al valore nullo !!!

La risposta sta tentando di analizzare è questo:

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

e, consentendo di debug, ottengo quei messaggi:

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 

e poi la 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 

Grazie a tutti quelli che mi possono aiutare!

risposta

8

Probabilmente hai un mix di classi JavaMail da due diverse versioni di JavaMail. Controlla il tuo classpath per altre istanze delle classi javax.mail. *, Magari in un j2ee.jar o javaee.jar.

10

Alla fine ho scoperto la causa del problema.

Sto includendo Apache Cxf nel mio progetto.

Cxf include un riferimento a geronimo-javamail_1.4_spec che sovrascrive alcune delle classi javamail.

Escludendo il riferimento a geronimo, tutto funziona correttamente!

+3

ho trascorso un periodo molto lungo giorno alla ricerca di questa soluzione.Una volta trovato il tuo post, mi ci è voluta solo mezz'ora per andare avanti. Grazie mille per aver trovato il tempo di mettere la tua domanda e la risposta qui. Ha fatto un'enorme differenza per me. – Spina

0

Avevo un problema simile (forse lo stesso).

Il problema era connesso al bug del server di posta descritto in questa Oracle FAQ here.

La soluzione è:

  • risolvere il bug nel server IMAP
  • O usare soluzione descritta in 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. 
    

o

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

ho trovato questo grazie a questo forum Oracle thread

0

Grazie per darmi suggerimenti per questo problema

aggiungo qui di seguito dipendenza nel mio progetto e tutto funziona correttamente

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