This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new 2b38814e Document CSVFormat validation exceptions
2b38814e is described below
commit 2b38814e50cee4582cbb29687a7516457e8b5834
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Nov 29 10:27:01 2026 -0500
Document CSVFormat validation exceptions
Add IllegalArgumentException documentation to Builder.get(), the
constructor, and deprecated with* methods for invalid or inconsistent
format settings.
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/csv/CSVFormat.java | 70 ++++++++++++++++------
2 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 86078232..6958cfe1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -82,6 +82,7 @@
<action type="fix" dev="ggregory" due-to="agamal026, Gary Gregory">Add
tests for line breaks in automatic CSV headers (#640).</action>
<action type="fix" dev="ggregory" due-to="Sharang Gupta, Gary
Gregory">Add missing @Test to
CSVFormatTest.testEqualsSkipHeaderRecord#testEqualsSkipHeaderRecord()
(#639).</action>
<action type="fix" dev="ggregory" due-to="Mohd Irshad, Gary Gregory">Fix
Predefined @see references in CSVFormat (#641).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Document
CSVFormat validation exceptions.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory, Indy, Sylvia van
Os" issue="CSV-307">Add an "Android Compatibility" section to the web
site.</action>
<action type="add" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory"
issue="CSV-325">Add CSVParser.Builder.setByteOffset(long) (#604).</action>
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index cc3192a0..8ae1f74e 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -321,6 +321,7 @@ public final class CSVFormat implements Serializable {
* Builds a new CSVFormat instance.
*
* @return A new CSVFormat instance.
+ * @throws IllegalArgumentException Thrown when any attribute is
invalid or inconsistent with other attributes.
* @since 1.13.0
*/
@Override
@@ -1534,7 +1535,7 @@ public final class CSVFormat implements Serializable {
*
* @param delimiter The char used for value separation, must not be a line
break character
* @return A new CSV format.
- * @throws IllegalArgumentException if the delimiter is a line break
character
+ * @throws IllegalArgumentException if the delimiter is a line break
character.
* @see #DEFAULT
* @see #RFC4180
* @see #MYSQL
@@ -1650,6 +1651,12 @@ public final class CSVFormat implements Serializable {
private transient Object writeLock = new Object();
+ /**
+ * Creates a new CSV format from the specified builder.
+ *
+ * @param builder The builder to use.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
+ */
private CSVFormat(final Builder builder) {
this.allowMissingColumnNames = builder.allowMissingColumnNames;
this.autoFlush = builder.autoFlush;
@@ -2766,7 +2773,7 @@ public final class CSVFormat implements Serializable {
* for parsing, so it cannot be used here.
* </p>
*
- * @throws IllegalArgumentException Throw when any attribute is invalid or
inconsistent with other attributes.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
*/
private void validate() throws IllegalArgumentException {
if (quoteCharacter != null && contains(delimiter,
quoteCharacter.charValue())) { // Explicit unboxing is intentional
@@ -2808,6 +2815,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} that allows duplicate header names.
*
* @return A new {@code CSVFormat} that allows duplicate header names
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.7
* @deprecated Use {@link Builder#setAllowDuplicateHeaderNames(boolean)
Builder#setAllowDuplicateHeaderNames(true)}
*/
@@ -2821,6 +2829,7 @@ public final class CSVFormat implements Serializable {
*
* @param allowDuplicateHeaderNames The duplicate header names behavior,
true to allow, false to disallow.
* @return A new {@code CSVFormat} with duplicate header names behavior
set to the given value.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.7
* @deprecated Use {@link Builder#setAllowDuplicateHeaderNames(boolean)}
*/
@@ -2834,6 +2843,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the missing column names behavior
of the format set to {@code true}.
*
* @return A new CSVFormat that is equal to this but with the specified
missing column names behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setAllowMissingColumnNames(boolean)
* @since 1.1
* @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)
Builder#setAllowMissingColumnNames(true)}
@@ -2849,6 +2859,7 @@ public final class CSVFormat implements Serializable {
* @param allowMissingColumnNames The missing column names behavior,
{@code true} to allow missing column names in the header line, {@code false} to
cause
* an {@link IllegalArgumentException} to
be thrown.
* @return A new CSVFormat that is equal to this but with the specified
missing column names behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)}
*/
@Deprecated
@@ -2861,6 +2872,7 @@ public final class CSVFormat implements Serializable {
*
* @param autoFlush whether to flush on close.
* @return A new CSVFormat that is equal to this but with the specified
autoFlush setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.6
* @deprecated Use {@link Builder#setAutoFlush(boolean)}
*/
@@ -2870,13 +2882,13 @@ public final class CSVFormat implements Serializable {
}
/**
- * Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character.
- *
- * Note that the comment start character is only recognized at the start
of a line.
+ * Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character. Note that the comment start character is
only
+ * recognized at the start of a line.
*
* @param commentMarker The comment start marker
* @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
+ * attributes.
* @deprecated Use {@link Builder#setCommentMarker(char)}
*/
@Deprecated
@@ -2885,13 +2897,13 @@ public final class CSVFormat implements Serializable {
}
/**
- * Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character.
- *
- * Note that the comment start character is only recognized at the start
of a line.
+ * Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character. Note that the comment start character is
only
+ * recognized at the start of a line.
*
* @param commentMarker The comment start marker, use {@code null} to
disable
* @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
+ * attributes.
* @deprecated Use {@link Builder#setCommentMarker(Character)}
*/
@Deprecated
@@ -2904,7 +2916,8 @@ public final class CSVFormat implements Serializable {
*
* @param delimiter The delimiter character
* @return A new CSVFormat that is equal to this with the specified
character as a delimiter
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
+ * attributes.
* @deprecated Use {@link Builder#setDelimiter(char)}
*/
@Deprecated
@@ -2917,7 +2930,8 @@ public final class CSVFormat implements Serializable {
*
* @param escape The escape character
* @return A new CSVFormat that is equal to this but with the specified
character as the escape character
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
+ * attributes.
* @deprecated Use {@link Builder#setEscape(char)}
*/
@Deprecated
@@ -2930,7 +2944,8 @@ public final class CSVFormat implements Serializable {
*
* @param escape The escape character, use {@code null} to disable
* @return A new CSVFormat that is equal to this but with the specified
character as the escape character
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
+ * attributes.
* @deprecated Use {@link Builder#setEscape(Character)}
*/
@Deprecated
@@ -2957,6 +2972,7 @@ public final class CSVFormat implements Serializable {
* The resulting format will have {@code skipHeaderRecord = true}.</p>
*
* @return A new CSVFormat that is equal to this but using the first
record as header.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setSkipHeaderRecord(boolean)
* @see Builder#setHeader(String...)
* @since 1.3
@@ -2993,6 +3009,7 @@ public final class CSVFormat implements Serializable {
*
* @param headerEnum The enum defining the header, {@code null} if
disabled, empty if parsed automatically, user specified otherwise.
* @return A new CSVFormat that is equal to this but with the specified
header
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setHeader(String...)
* @see Builder#setSkipHeaderRecord(boolean)
* @since 1.3
@@ -3022,6 +3039,7 @@ public final class CSVFormat implements Serializable {
*
* @param resultSet The resultSet for the header, {@code null} if
disabled, empty if parsed automatically, user-specified otherwise.
* @return A new CSVFormat that is equal to this but with the specified
header
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @throws SQLException SQLException if a database access error occurs or
this method is called on a closed result set.
* @since 1.1
* @deprecated Use {@link Builder#setHeader(ResultSet)}
@@ -3050,6 +3068,7 @@ public final class CSVFormat implements Serializable {
*
* @param resultSetMetaData The metaData for the header, {@code null} if
disabled, empty if parsed automatically, user specified otherwise.
* @return A new CSVFormat that is equal to this but with the specified
header
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @throws SQLException SQLException if a database access error occurs or
this method is called on a closed result set.
* @since 1.1
* @deprecated Use {@link Builder#setHeader(ResultSetMetaData)}
@@ -3078,6 +3097,7 @@ public final class CSVFormat implements Serializable {
*
* @param header The header, {@code null} if disabled, empty if parsed
automatically, user-specified otherwise.
* @return A new CSVFormat that is equal to this but with the specified
header
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setSkipHeaderRecord(boolean)
* @deprecated Use {@link Builder#setHeader(String...)}
*/
@@ -3096,6 +3116,7 @@ public final class CSVFormat implements Serializable {
*
* @param headerComments The headerComments which will be printed by the
Printer before the actual CSV data.
* @return A new CSVFormat that is equal to this but with the specified
header
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setSkipHeaderRecord(boolean)
* @since 1.1
* @deprecated Use {@link Builder#setHeaderComments(Object...)}
@@ -3109,6 +3130,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the empty line skipping behavior of
the format set to {@code true}.
*
* @return A new CSVFormat that is equal to this but with the specified
empty line skipping behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setIgnoreEmptyLines(boolean)
* @since 1.1
* @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)
Builder#setIgnoreEmptyLines(true)}
@@ -3124,6 +3146,7 @@ public final class CSVFormat implements Serializable {
* @param ignoreEmptyLines The empty line skipping behavior, {@code true}
to ignore the empty lines between the records, {@code false} to translate empty
* lines to empty records.
* @return A new CSVFormat that is equal to this but with the specified
empty line skipping behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)}
*/
@Deprecated
@@ -3135,6 +3158,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the header ignore case behavior set
to {@code true}.
*
* @return A new CSVFormat that will ignore the new case header name
behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setIgnoreHeaderCase(boolean)
* @since 1.3
* @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)
Builder#setIgnoreHeaderCase(true)}
@@ -3149,6 +3173,7 @@ public final class CSVFormat implements Serializable {
*
* @param ignoreHeaderCase The case mapping behavior, {@code true} to
access name/values, {@code false} to leave the mapping as is.
* @return A new CSVFormat that will ignore case header name if specified
as {@code true}
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
* @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)}
*/
@@ -3161,6 +3186,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the parser trimming behavior of the
format set to {@code true}.
*
* @return A new CSVFormat that is equal to this but with the specified
parser trimming behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setIgnoreSurroundingSpaces(boolean)
* @since 1.1
* @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)
Builder#setIgnoreSurroundingSpaces(true)}
@@ -3175,6 +3201,7 @@ public final class CSVFormat implements Serializable {
*
* @param ignoreSurroundingSpaces The parser trimming behavior, {@code
true} to remove the surrounding spaces, {@code false} to leave the spaces as is.
* @return A new CSVFormat that is equal to this but with the specified
trimming behavior.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)}
*/
@Deprecated
@@ -3191,6 +3218,7 @@ public final class CSVFormat implements Serializable {
*
* @param nullString The String to convert to and from {@code null}. No
substitution occurs if {@code null}
* @return A new CSVFormat that is equal to this but with the specified
null conversion string.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setNullString(String)}
*/
@Deprecated
@@ -3203,7 +3231,7 @@ public final class CSVFormat implements Serializable {
*
* @param quoteChar The quote character
* @return A new CSVFormat that is equal to this but with the specified
character as quoteChar
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or any attribute is invalid or inconsistent with other attributes.
* @deprecated Use {@link Builder#setQuote(char)}
*/
@Deprecated
@@ -3216,7 +3244,7 @@ public final class CSVFormat implements Serializable {
*
* @param quoteChar The quote character, use {@code null} to disable.
* @return A new CSVFormat that is equal to this but with the specified
character as quoteChar
- * @throws IllegalArgumentException thrown if the specified character is a
line break
+ * @throws IllegalArgumentException thrown if the specified character is a
line break, or any attribute is invalid or inconsistent with other attributes.
* @deprecated Use {@link Builder#setQuote(Character)}
*/
@Deprecated
@@ -3229,6 +3257,7 @@ public final class CSVFormat implements Serializable {
*
* @param quoteMode The quote policy to use for output.
* @return A new CSVFormat that is equal to this but with the specified
quote policy
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setQuoteMode(QuoteMode)}
*/
@Deprecated
@@ -3246,6 +3275,7 @@ public final class CSVFormat implements Serializable {
*
* @param recordSeparator The record separator to use for output.
* @return A new CSVFormat that is equal to this but with the specified
output record separator
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setRecordSeparator(char)}
*/
@Deprecated
@@ -3255,7 +3285,6 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the record separator of the format
set to the specified String.
- *
* <p>
* <strong>Note:</strong> This setting is only used during printing and
does not affect parsing. Parsing currently only works for inputs with '\n',
'\r' and
* "\r\n"
@@ -3263,7 +3292,7 @@ public final class CSVFormat implements Serializable {
*
* @param recordSeparator The record separator to use for output.
* @return A new CSVFormat that is equal to this but with the specified
output record separator
- * @throws IllegalArgumentException if recordSeparator is none of CR, LF
or CRLF
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @deprecated Use {@link Builder#setRecordSeparator(String)}
*/
@Deprecated
@@ -3275,6 +3304,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with skipping the header record set to
{@code true}.
*
* @return A new CSVFormat that is equal to this but with the specified
skipHeaderRecord setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setSkipHeaderRecord(boolean)
* @see Builder#setHeader(String...)
* @since 1.1
@@ -3290,6 +3320,7 @@ public final class CSVFormat implements Serializable {
*
* @param skipHeaderRecord whether to skip the header record.
* @return A new CSVFormat that is equal to this but with the specified
skipHeaderRecord setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setHeader(String...)
* @deprecated Use {@link Builder#setSkipHeaderRecord(boolean)}
*/
@@ -3308,6 +3339,7 @@ public final class CSVFormat implements Serializable {
* </p>
*
* @return A new CSVFormat that is equal to this but with the operating
system's line separator string.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.6
* @deprecated Use {@link Builder#setRecordSeparator(String)
setRecordSeparator(System.lineSeparator())}
*/
@@ -3320,6 +3352,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} to add a trailing delimiter.
*
* @return A new CSVFormat that is equal to this but with the trailing
delimiter setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
* @deprecated Use {@link Builder#setTrailingDelimiter(boolean)
Builder#setTrailingDelimiter(true)}
*/
@@ -3333,6 +3366,7 @@ public final class CSVFormat implements Serializable {
*
* @param trailingDelimiter whether to add a trailing delimiter.
* @return A new CSVFormat that is equal to this but with the specified
trailing delimiter setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
* @deprecated Use {@link Builder#setTrailingDelimiter(boolean)}
*/
@@ -3345,6 +3379,7 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} to trim leading and trailing blanks. See
{@link #getTrim()} for details of where this is used.
*
* @return A new CSVFormat that is equal to this but with the trim setting
on.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
* @deprecated Use {@link Builder#setTrim(boolean) Builder#setTrim(true)}
*/
@@ -3358,6 +3393,7 @@ public final class CSVFormat implements Serializable {
*
* @param trim whether to trim leading and trailing blanks.
* @return A new CSVFormat that is equal to this but with the specified
trim setting.
+ * @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
* @deprecated Use {@link Builder#setTrim(boolean)}
*/