This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 135522

Summary: Do not add @SuppressWarnings("unchecked") promiscuously
Product: guibuilder Reporter: Jesse Glick <jglick>
Component: CodeAssignee: Jan Stola <jstola>
Status: NEW ---    
Severity: blocker CC: msauer
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description Jesse Glick 2008-05-21 16:47:53 UTC
#8ce717457624 added this annotation to every Swing form. This is bad. @SW should be used only where absolutely
necessary, and most Swing forms do not need it at all; apparently it is only needed for some code associated with
BeansBinding and JPA (I am assuming you cannot just use e.g. Collections.checkedCollection). For such cases, @SW should
instead be applied to the particular local variable that requires it.
Comment 1 Jan Stola 2008-05-22 13:23:27 UTC
> This is bad.

Can you elaborate on this. Is this just an academic/aesthetic/purely theoretical problem? Or it really breaks anything? 
Note that this annotation affects code generated by GUI builder only. There's is no benefit in distracting the user by 
some warnings that we cannot avoid. Moreover, the annotation is outside the guarded block and can be removed if really 
needed (why?). I don't believe that it is worth the effort to implement a complex logic to add this annotation only 
when it is really necessary. We would even have to add a heuristic to avoid repeated addition of annotation removed by 
the user for some (strange) reason.
Comment 2 Jesse Glick 2008-05-22 21:33:11 UTC
Because you should be able to do a Find Usages on @SuppressWarnings in your code to look for inappropriate suppression
of warnings by other developers (or maybe yourself). Warnings are there for a reason - to protect you from dumb mistakes
- and suppressing them should be a last resort.

I doubt that it is really "complex logic" to add it to appropriate local variables. Instead of generating

List<String> boundBeanThingy = (List) BeansBinder.makeBinding("whatever");


List<String> boundBeanThingy = (List) BeansBinder.makeBinding("whatever");


List<String> boundBeanThingy = Collections.checkedCollection((List) BeansBinder.makeBinding("whatever"), String.class);

Not a very big change.