commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [discuss][Digester] The future of Digester an the Digester3 in sandbox
Date Tue, 01 Mar 2011 15:04:08 GMT
On 1 March 2011 08:00, Jörg Schaible <joerg.schaible@scalaris.com> wrote:
> Hi Simone,
>
> Simone Tripodi wrote:
>
> [snip]
>
>
>> @SuppressWarnings("unchecked")
>> public <T> T parse(InputSource input, Class<T> returnedType) throws
>> IOException, SAXException {
>>  .
>>  .
>>  .
>>  return returnedType.cast(this.root);
>> }
>
> It would be nice, if we can start to avoid such method global suppressions,
> because it hides possibly unwanted stuff. You can always assign the
> annotation directly to a variable instead:
>
> @SuppressWarnings("unchecked")
> T t = returnedType.cast(this.root);
> return t;

I would go a bit further and say that @SuppressWarnings should not be
used unless you can prove that the cast is always valid (as may well
be the case here - I've not checked), and that this should be
documented in a // comment on the annotation, e.g.

@SuppressWarnings("unchecked") // OK because etc.

Otherwise, the annotation effectively gives the compiler permission to
cause a ClassCastException somewhere else at some point in the future.

As with many forms of suppression, the risk is that there will be a
bad reaction later ...


> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Mime
View raw message