Skip to content

Commit 33c004f

Browse files
committed
Invalid use of == to compare Character equality; add tests to detect this
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1398357 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6f94c8a commit 33c004f

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ void validate() throws IllegalStateException {
205205
"')");
206206
}
207207

208-
if (quoteChar != null && quoteChar == commentStart) {
208+
if (quoteChar != null && quoteChar.equals(commentStart)) {
209209
throw new IllegalStateException("The comment start character and the quoteChar cannot be the same ('" + commentStart +
210210
"')");
211211
}
212212

213-
if (escape != null && escape == commentStart) {
213+
if (escape != null && escape.equals(commentStart)) {
214214
throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')");
215215
}
216216

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ public void testValidation() {
140140
// expected
141141
}
142142

143+
// Cannot assume that callers won't use different Character objects
144+
try {
145+
format.withQuoteChar(new Character('!')).withCommentStart('!').validate();
146+
fail();
147+
} catch (final IllegalStateException e) {
148+
// expected
149+
}
150+
143151
format.withQuoteChar(null).withCommentStart(null).validate();
144152

145153
try {
@@ -149,6 +157,14 @@ public void testValidation() {
149157
// expected
150158
}
151159

160+
// Cannot assume that callers won't use different Character objects
161+
try {
162+
format.withEscape(new Character('!')).withCommentStart(new Character('!')).validate();
163+
fail();
164+
} catch (final IllegalStateException e) {
165+
// expected
166+
}
167+
152168
format.withEscape(null).withCommentStart(null).validate();
153169

154170

@@ -165,7 +181,7 @@ public void testValidation() {
165181
} catch (final IllegalStateException e) {
166182
// expected
167183
}
168-
}
184+
}
169185

170186
@SuppressWarnings("boxing") // no need to worry about boxing here
171187
@Test

0 commit comments

Comments
 (0)