Bug in JAF 1.1 (ObjectDataContentHandler)

"Markus Wiederkehr" <[email protected]> Wed, 10 May 2006 16:43:40 +0200
Newsgroups gmane.comp.java.classpath.extensions.discuss
Message-ID <[email protected]>
I tried to send an e-mail using GNU JavaMail 1.1.1 in combination with
GNU Activation 1.1 with this simple code:

>  Session session =3D Session.getInstance(new Properties());
>  MimeMessage mm =3D new MimeMessage(session);
>
>  mm.setSender(new InternetAddress(sender));
>  mm.setRecipient(RecipientType.TO, new InternetAddress(recipient));
>  mm.setSubject(subject);
>  mm.setText(message);
>
>  Transport transport =3D session.getTransport("smtp");
>  transport.connect(host_, port_, "", "");
>  Address[] recipients =3D { new InternetAddress(recipient) };
>  transport.sendMessage(mm, recipients);

This led to the following exception:

> javax.mail.SendFailedException: no object DCH for MIME type text/plain; c=
harset=3DUTF-8
>     at gnu.mail.providers.smtp.SMTPTransport.sendMessage(SMTPTransport.ja=
va:520)

Tracking down the problem I found this code in
javax.activation.ObjectDataContentHandler:

>  public void writeTo(Object object, String mimeType, OutputStream out)
>    throws IOException
>  {
>    if (dch !=3D null)
>      {
>        dch.writeTo(object, mimeType, out);
>      }
>    throw new UnsupportedDataTypeException("no object DCH for MIME type " =
+ mimeType);
>  }

This method seems to have a bug because the exception gets thrown even
if dch is not null. Changing this method to following solved the
problem:

>  public void writeTo(Object object, String mimeType, OutputStream out)
>    throws IOException
>  {
>    if (dch =3D=3D null)
>      throw new UnsupportedDataTypeException("no object DCH for MIME type =
" + mimeType);
>
>    dch.writeTo(object, mimeType, out);
>  }

I hope this is useful to someone...

Markus

--=20
Always remember you're unique. Just like everyone else.