commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r582444 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java
Date Sat, 06 Oct 2007 04:10:49 GMT
Author: bayard
Date: Fri Oct  5 21:10:48 2007
New Revision: 582444

URL: http://svn.apache.org/viewvc?rev=582444&view=rev
Log:
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

Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java?rev=582444&r1=582443&r2=582444&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/StringEncoderComparator.java
Fri Oct  5 21:10:48 2007
@@ -36,13 +36,15 @@
     /**
      * Internal encoder instance.
      */
-    private StringEncoder stringEncoder;
+    private final StringEncoder stringEncoder;
 
     /**
      * Constructs a new instance.
+     * @deprecated as creating without a StringEncoder will lead to a 
+     *             broken NullPointerException creating comparator.
      */
     public StringEncoderComparator() {
-        // no init.
+        stringEncoder = null;   // Trying to use this will cause things to break
     }
 
     /**
@@ -71,8 +73,8 @@
         int compareCode = 0;
 
         try {
-            Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1);
-            Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2);
+            Comparable s1 = (Comparable) this.stringEncoder.encode(o1);
+            Comparable s2 = (Comparable) this.stringEncoder.encode(o2);
             compareCode = s1.compareTo(s2);
         } 
         catch (EncoderException ee) {



Mime
View raw message