Skip to content

Commit ae47fb8

Browse files
committed
CSVFormat.validate() throws IllegalStateException instead of IllegalArgumentException because the method validates the state of the object.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1397876 13f79535-47bb-0310-9956-ffa450edef68
1 parent e331df6 commit ae47fb8

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,31 @@ private static boolean isLineBreak(final Character c) {
168168
}
169169

170170
/**
171-
* Verifies the consistency of the parameters and throws an IllegalArgumentException if necessary.
171+
* Verifies the consistency of the parameters and throws an IllegalStateException if necessary.
172+
*
173+
* @throws IllegalStateException
172174
*/
173-
void validate() throws IllegalArgumentException {
175+
void validate() throws IllegalStateException {
174176
if (delimiter == encapsulator) {
175-
throw new IllegalArgumentException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")");
177+
throw new IllegalStateException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")");
176178
}
177179

178180
if (delimiter == escape) {
179-
throw new IllegalArgumentException("The escape character and the delimiter cannot be the same ('" + escape + "')");
181+
throw new IllegalStateException("The escape character and the delimiter cannot be the same ('" + escape + "')");
180182
}
181183

182184
if (delimiter == commentStart) {
183-
throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same ('" + commentStart +
185+
throw new IllegalStateException("The comment start character and the delimiter cannot be the same ('" + commentStart +
184186
"')");
185187
}
186188

187189
if (encapsulator != null && encapsulator == commentStart) {
188-
throw new IllegalArgumentException("The comment start character and the encapsulator cannot be the same ('" + commentStart +
190+
throw new IllegalStateException("The comment start character and the encapsulator cannot be the same ('" + commentStart +
189191
"')");
190192
}
191193

192194
if (escape != null && escape == commentStart) {
193-
throw new IllegalArgumentException("The comment start and the escape character cannot be the same ('" + commentStart + "')");
195+
throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')");
194196
}
195197
}
196198

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ public void testValidation() {
113113
try {
114114
format.withDelimiter('!').withEscape('!').validate();
115115
fail();
116-
} catch (final IllegalArgumentException e) {
116+
} catch (final IllegalStateException e) {
117117
// expected
118118
}
119119

120120
try {
121121
format.withDelimiter('!').withCommentStart('!').validate();
122122
fail();
123-
} catch (final IllegalArgumentException e) {
123+
} catch (final IllegalStateException e) {
124124
// expected
125125
}
126126

127127
try {
128128
format.withEncapsulator('!').withCommentStart('!').validate();
129129
fail();
130-
} catch (final IllegalArgumentException e) {
130+
} catch (final IllegalStateException e) {
131131
// expected
132132
}
133133

@@ -136,7 +136,7 @@ public void testValidation() {
136136
try {
137137
format.withEscape('!').withCommentStart('!').validate();
138138
fail();
139-
} catch (final IllegalArgumentException e) {
139+
} catch (final IllegalStateException e) {
140140
// expected
141141
}
142142

@@ -146,7 +146,7 @@ public void testValidation() {
146146
try {
147147
format.withEncapsulator('!').withDelimiter('!').validate();
148148
fail();
149-
} catch (final IllegalArgumentException e) {
149+
} catch (final IllegalStateException e) {
150150
// expected
151151
}
152152
}

0 commit comments

Comments
 (0)