users@jsr311.java.net

Re: Valid paramer types and exception handling

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 14 Jan 2009 11:27:58 -0500

On Jan 14, 2009, at 10:24 AM, Sergey Beryozkin wrote:
>
> Section 3.2 says that types which have a constructor that accepts a
> single String argument or a static method valueOf(String) are
> supported. Also, the section says that WebApplicationException needs
> to be thrown if exception occurs during the object construction
> (using constructor or valueOf)
>
> few questions.
>
> 1. what should happen if a given parameter type has no valid
> constructor or valueOf() - should an exception be thrown or a null
> value returned ?
>
That is not currently defined in the spec, its something you could
pick up during initialization/validation rather than at runtime. That
said, it seems like a 500 would be most appropriate if validation is
delayed until runtime.

> 2. Some Java types such as java.util.UUID have no valueOf(String)
> but have fromString(String) method instead. Would it make sense to
> have such methods evaluated too ?
>
Yes, that would also get round an issue with Enum where you can't
override the valueOf method. I'll add this to the maintenance release
unless there are objections ?

> 3. What HTTP status code should be set if an exception occurs during
> a @FormParam parameter construction - 404 or 400
>
I think 400 would be most appropriate. I'll add this to the
maintenance release unless there are objections ?

> 4. If a field initialization fails due to SecurityManager
> restrictions then will it also be treated as a client error ?

Seems like a 500 would be most appropriate since the error is due to
misconfiguration on the server side.

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.