commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (CODEC-141) Generics warnings for StringEncoderComparator
Date Mon, 08 Apr 2013 17:41:15 GMT


Sebb commented on CODEC-141:

Agreed it should ideally implement Comparator<String>.

Unfortunately it's not possible to do so without breaking binary compat., as it's not possible
to provide both

public int compare(String, String) // needed to implement Comparator<String>
public int compare(Object, Object) // needed to ensure binary compat.

The compiler reports a name clash, as they have the same erasure.

This problem arises in part because StringEncoder extends Encoder.

> Generics warnings for StringEncoderComparator
> ---------------------------------------------
>                 Key: CODEC-141
>                 URL:
>             Project: Commons Codec
>          Issue Type: Bug
>            Reporter: Sebb
>         Attachments: CODEC-141.patch
> The StringEncoderComparator class currently extends the raw type Comparator.
> I think it should extend Comparator<Object>, as it implements compare(Object, Object).
> Although it is documented as being a String comparator, some StringEncoder implementations
also support other types such as byte[].
> Secondly, its compare() method currently casts the stringEncoder.encode() results to
> This might as well be String, as that is what a StringEncoder is supposed to do.
> If a class cast exception occurs, then this is a bug in the provided StringEncoder (and
casting to Comparable would likely also fail).

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message