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.
Assume you manage a collection of objects. Consider the methods: Object findByPropertyValue(String name, Object value); Object findByPropertyValue(String name, String value, boolean ignoreCase); Object findByPropertyValue(String name, Object value boolean ignoreCase); The first two are public methods which simply call the private third method to avoid having to have an 'ignoreCase' parameter for anything but Strings. In the second (public) method, in order to call the private method with the same name, you need to tell the compiler you want the private method instead of recursively calling the original method by explicitly casting the "value" parameter to Object: return findByPropertyValue(name, (Object)value, ignoreCase); ------ The above line incorrectly shows the hint "Unnecessary cast to Object", since it is needed in this case to select the correct method.
Additional problems: First, it offers to disable/configure the "type cast is too strong" hint instead of itself. Also, consider this case: Map<String, Object> Map; Object foo; ... if (map.containsKey((String)foo)) { ... } ------ The "unnecessary cast" hint is incorrectly displayed, since without the cast the "suspicious call" hint is displayed. And this case: Collection c = (Collection)accessor.invoke(entity, (Object[])null); -------- Without the cast the "non-varargs call of varargs method with inexact argument type" hint is shown.
Svata, please contact me offline, I have a few comments. Thanks.
This also happens with simple types. Consider the following simple exemple: int a=2, b=5; double x = a/b; // x = 0.0 double y = ((double) a)/b; // y = 0.4 The editor displays the hint "unnecessary cast to double" for the calculation of 'y' whereas the cast obviously changes the result.
Another case of the same problem. Let c a char variable. Consider an expression like "Character " + c + " has ASCII code " + (int)c --- Generally speaking, the "unnecessary cast" hint does not take into account if the (up)cast is relevant in the expression where it occurs, either to select the right method/operator, or to suppress a warning, etc.
*** Bug 235668 has been marked as a duplicate of this bug. ***
I would split the issue to method resolution and the arithmetic expression issues. I copied arithmetic stuff in comment #3 and comment #4 to issue #237553. Please track only method resolution-related issues here.
varargs and overloaded methods handling fixed in http://hg.netbeans.org/jet-main/rev/2b7422a28f83
*** Bug 237054 has been marked as a duplicate of this bug. ***
Integrated into 'main-silver', will be available in build *201311060001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/2b7422a28f83 User: Svata Dedic <sdedic@netbeans.org> Log: #229951: avoided hints for calls to overloaded methods which may become ambiguous. Improved varargs handling