Skip to content

Commit 71e7260

Browse files
committed
stringEncoder variable is now final to tighten it up, the empty constructor is deprecated as it will only lead to a broken NPE producing comparator and I've removed the unnecessary casting
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@582444 13f79535-47bb-0310-9956-ffa450edef68
1 parent c046759 commit 71e7260

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/java/org/apache/commons/codec/StringEncoderComparator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public class StringEncoderComparator implements Comparator {
3636
/**
3737
* Internal encoder instance.
3838
*/
39-
private StringEncoder stringEncoder;
39+
private final StringEncoder stringEncoder;
4040

4141
/**
4242
* Constructs a new instance.
43+
* @deprecated as creating without a StringEncoder will lead to a
44+
* broken NullPointerException creating comparator.
4345
*/
4446
public StringEncoderComparator() {
45-
// no init.
47+
stringEncoder = null; // Trying to use this will cause things to break
4648
}
4749

4850
/**
@@ -71,8 +73,8 @@ public int compare(Object o1, Object o2) {
7173
int compareCode = 0;
7274

7375
try {
74-
Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1);
75-
Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2);
76+
Comparable s1 = (Comparable) this.stringEncoder.encode(o1);
77+
Comparable s2 = (Comparable) this.stringEncoder.encode(o2);
7678
compareCode = s1.compareTo(s2);
7779
}
7880
catch (EncoderException ee) {

0 commit comments

Comments
 (0)