commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1398357 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVFormat.java test/java/org/apache/commons/csv/CSVFormatTest.java
Date Mon, 15 Oct 2012 16:04:30 GMT
Author: sebb
Date: Mon Oct 15 16:04:29 2012
New Revision: 1398357

URL: http://svn.apache.org/viewvc?rev=1398357&view=rev
Log:
Invalid use of == to compare Character equality; add tests to detect this

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1398357&r1=1398356&r2=1398357&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Mon Oct 15
16:04:29 2012
@@ -205,12 +205,12 @@ public class CSVFormat implements Serial
                     "')");
         }
 
-        if (quoteChar != null && quoteChar == commentStart) {
+        if (quoteChar != null && quoteChar.equals(commentStart)) {
             throw new IllegalStateException("The comment start character and the quoteChar
cannot be the same ('" + commentStart + 
                     "')");
         }
 
-        if (escape != null && escape == commentStart) {
+        if (escape != null && escape.equals(commentStart)) {
             throw new IllegalStateException("The comment start and the escape character cannot
be the same ('" + commentStart + "')");
         }
 

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1398357&r1=1398356&r2=1398357&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Oct
15 16:04:29 2012
@@ -140,6 +140,14 @@ public class CSVFormatTest {
             // expected
         }
 
+        // Cannot assume that callers won't use different Character objects
+        try {
+            format.withQuoteChar(new Character('!')).withCommentStart('!').validate();
+            fail();
+        } catch (final IllegalStateException e) {
+            // expected
+        }
+
         format.withQuoteChar(null).withCommentStart(null).validate();
 
         try {
@@ -149,6 +157,14 @@ public class CSVFormatTest {
             // expected
         }
 
+        // Cannot assume that callers won't use different Character objects
+        try {
+            format.withEscape(new Character('!')).withCommentStart(new Character('!')).validate();
+            fail();
+        } catch (final IllegalStateException e) {
+            // expected
+        }
+
         format.withEscape(null).withCommentStart(null).validate();
 
 
@@ -165,7 +181,7 @@ public class CSVFormatTest {
         } catch (final IllegalStateException e) {
             // expected
         }
-}
+    }
 
     @SuppressWarnings("boxing") // no need to worry about boxing here
     @Test



Mime
View raw message