james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Markus Wiederkehr" <markus.wiederk...@gmail.com>
Subject Re: [mime4j] MimeException in Field.parse()
Date Sun, 09 Nov 2008 19:46:04 GMT
On Sun, Nov 9, 2008 at 8:33 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> On Sat, 2008-11-08 at 14:31 +0100, Markus Wiederkehr wrote:
>> For MIME4J-73 we changed the IllegalArgumentException in Field.parse()
>> to a MimeException because loading an invalid message from an
>> InputStream should not throw a runtime exception.
>>
>> While this was correct it leads to another problem. Loading a message
>> from an InputStream is just one scenario. The other one is creating a
>> new message from scratch. If you know for certain that the header
>> field to parse is well-formed the MimeException is nothing but a
>> nuisance.
>>
>> So maybe what we need is a checked exception for loading a message and
>> a runtime exception for creating a message programatically. Maybe
>> Field.parse() should throw an IllegalArgumentException and the code
>> that loads a message should convert it to a MimeException.
>>
>
> While Field.parse() throwing a checked exception can be a nuisance, I
> personally can live with that. The idea of rethrowing
> IllegalArgumentException as a checked exception does not sound quite
> right to me.

Throw an IllegalArgumentException as a checked exception? I'm not sure
I understand..

What I meant is Field.parse() is called by Header.Header(InputStream),
MessageBuilder.field() and SimpleContentHandler.field(). Field.parse()
could throw an IllegalArgumentException which gets caught in these
three methods and rethrown as a MimeException.

What would you think of not throwing an exception at all?

The exception gets thrown if the header does not match the
FIELD_NAME_PATTERN. In this case Field.parse() could return a
"InvalidField" instance, for example. InvalidField.getName() could
return the raw value and getBody() could return either null or an
empty string.

Markus

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message