Issue 62 in sarasvati: getAttribute and Boolean.class unboxing

0 views
Skip to first unread message

sara...@googlecode.com

unread,
Jun 16, 2010, 11:32:17 AM6/16/10
to sarasvati...@googlegroups.com
Status: New
Owner: ----

New issue 62 by mmikulicic: getAttribute and Boolean.class unboxing
http://code.google.com/p/sarasvati/issues/detail?id=62

I noticed a usability problem with the new getAttribute API.

I used to do:

if(env.getBooleanAttribute("someattr")) ...

and if the attribute wasn't there it was treated as false.

now, I cannot do simply:

if(env.getAttribute("someattr", Boolean.class)) ...

because if "someattr" doesn't exist, the getAttribute would return null
which then gets autounboxed to the primitive boolean type by the compiler,
and throws a NPE.


This is caused by the fact that the null check happens too early, in the
generic code:

public static <T> T stringToObject (final String string, final Class<T>
type)
{
if ( string == null )
{
return null;
}
....


without allowing the type specific converter (if any) to handle a per-type
defaulting.

I don't know if a per-type defaulting would be useful in general, but I
feel that at least BooleanAttributeConverter should.

sara...@googlecode.com

unread,
Jun 16, 2010, 11:37:36 AM6/16/10
to sarasvati...@googlegroups.com

Comment #1 on issue 62 by mmikulicic: getAttribute and Boolean.class
unboxing
http://code.google.com/p/sarasvati/issues/detail?id=62

Currently I rewritten all my code to:

if ("true".equals(token.getEnv().getAttribute("someattr")))


sara...@googlecode.com

unread,
Jun 16, 2010, 12:55:14 PM6/16/10
to sarasvati...@googlegroups.com

Comment #2 on issue 62 by plorenz: getAttribute and Boolean.class unboxing
http://code.google.com/p/sarasvati/issues/detail?id=62

There's a version that takes a default value. How do you feel about:

if(env.getAttribute("someattr", Boolean.class, false))

sara...@googlecode.com

unread,
Jul 23, 2011, 11:45:02 PM7/23/11
to sarasvati...@googlegroups.com
Updates:
Status: WontFix
Owner: plor...@gmail.com

Comment #3 on issue 62 by plor...@gmail.com: getAttribute and Boolean.class
unboxing
http://code.google.com/p/sarasvati/issues/detail?id=62

Closing "Won't fix", no response to last comment.

Reply all
Reply to author
Forward
0 new messages