DirectoryStreamFilters.anyOf and allOf are not safe
Alan Bateman
Alan.Bateman at Sun.COM
Thu Oct 23 04:48:03 PDT 2008
Rémi Forax wrote:
> There is three differents bugs :
> 1) anyOf() of use a raw type as return type:
> <T extends FileRef> DirectoryStream.Filter anyOf(final
> DirectoryStream.Filter<? extends T>... filters)
> --------------------------------------------------------^
> there is no T here !
I'm not sure how I missed that - thanks!
>
> This bug is not currently detected by javac but will be soon,
> see http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types
Yes, this will be useful as some of the compiler errors when you use raw
types in error can be very mis-leading.
>
> 2) Java doesn't allow to create an array of parameteried types so
> declaring a varargs of parameterized type is not a good idea.
> It's better to use an Iterable here.
>
> 3) casting a DirectoryStream.Filter<? extends T> to a
> DirectoryStream.Filter<T> is unsafe and will lead to CCE.
> As Mark Thornton wrote the JDK should use DirectoryStream.Filter<?
> super T>.
>
> anyOf should be written like that:
> public static <T extends FileRef> DirectoryStream.Filter<T>
> anyOf(final Iterable<? extends DirectoryStream.Filter<? super T>>
> filters) {
>
Gee, I goofed here - thanks for finding this! Your proposed signature
looks good although it's not currently working as expected with javac
(Maurizio directed me to 6638712). Also using an Iterable requires a bit
of extra work. In any case, I'll try to get these signature corrected
for the next build.
Thanks again,
-Alan.
More information about the nio-dev
mailing list