From ae47fb8432095e48b8e754c767bb9037dfa5c5fa Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Sat, 13 Oct 2012 16:08:44 +0000 Subject: [PATCH] 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 --- .../java/org/apache/commons/csv/CSVFormat.java | 16 +++++++++------- .../org/apache/commons/csv/CSVFormatTest.java | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 32561cb5..5d8082a9 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -168,29 +168,31 @@ public class CSVFormat implements Serializable { } /** - * Verifies the consistency of the parameters and throws an IllegalArgumentException if necessary. + * Verifies the consistency of the parameters and throws an IllegalStateException if necessary. + * + * @throws IllegalStateException */ - void validate() throws IllegalArgumentException { + void validate() throws IllegalStateException { if (delimiter == encapsulator) { - throw new IllegalArgumentException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")"); + throw new IllegalStateException("The encapsulator character and the delimiter cannot be the same ('" + encapsulator + ")"); } if (delimiter == escape) { - throw new IllegalArgumentException("The escape character and the delimiter cannot be the same ('" + escape + "')"); + throw new IllegalStateException("The escape character and the delimiter cannot be the same ('" + escape + "')"); } if (delimiter == commentStart) { - throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same ('" + commentStart + + throw new IllegalStateException("The comment start character and the delimiter cannot be the same ('" + commentStart + "')"); } if (encapsulator != null && encapsulator == commentStart) { - throw new IllegalArgumentException("The comment start character and the encapsulator cannot be the same ('" + commentStart + + throw new IllegalStateException("The comment start character and the encapsulator cannot be the same ('" + commentStart + "')"); } if (escape != null && escape == commentStart) { - throw new IllegalArgumentException("The comment start and the escape character cannot be the same ('" + commentStart + "')"); + throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')"); } } diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index 30991864..e6c72d42 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -113,21 +113,21 @@ public class CSVFormatTest { try { format.withDelimiter('!').withEscape('!').validate(); fail(); - } catch (final IllegalArgumentException e) { + } catch (final IllegalStateException e) { // expected } try { format.withDelimiter('!').withCommentStart('!').validate(); fail(); - } catch (final IllegalArgumentException e) { + } catch (final IllegalStateException e) { // expected } try { format.withEncapsulator('!').withCommentStart('!').validate(); fail(); - } catch (final IllegalArgumentException e) { + } catch (final IllegalStateException e) { // expected } @@ -136,7 +136,7 @@ public class CSVFormatTest { try { format.withEscape('!').withCommentStart('!').validate(); fail(); - } catch (final IllegalArgumentException e) { + } catch (final IllegalStateException e) { // expected } @@ -146,7 +146,7 @@ public class CSVFormatTest { try { format.withEncapsulator('!').withDelimiter('!').validate(); fail(); - } catch (final IllegalArgumentException e) { + } catch (final IllegalStateException e) { // expected } }