Reports on declarations of Collection variables made by using the collection class as the type, rather than an appropriate interface.
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).
In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
'String.indexOf()' expression is replaceable with 'contains()'
Reports any String.indexOf() expressions which can be replaced with a call to the String.contains() method available in Java 5 and newer.
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
Reports for loops which iterate over collections or arrays, and can be replaced with an enhanced for loop (i.e. the foreach iteration syntax).
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
fixes for 137235 (contributed by Ron): more intelligent logic for determining if a path entry is a jar/zip (don't just rely on suffix, some new .bndl files seem to be becoming popular...)
partial fix for bug 31724 emits file:line numbers for declare warning/error.
This adds an optional "context" String to IMessage.
The IMessage creator should create a context String (or use an implementation that lazily creates one).
The IMessage client can render their messages without context embedded in the message field.
Emitting source context from the weaver will be harder.
Using file and start/end line will probably work, since tool clients can map to any available source file paths.
(BcelSourceContext and BcelShadow can be updated with end from range.)