@@ -96,29 +96,39 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
9696 * Creates a parser for the given {@link File}.
9797 *
9898 * @param file
99- * a CSV file
99+ * a CSV file. Must not be null.
100100 * @param format
101- * the CSVFormat used for CSV parsing
101+ * the CSVFormat used for CSV parsing. Must not be null.
102102 * @return a new parser
103+ * @throws IllegalArgumentException
104+ * If the parameters of the format are inconsistent or if either file or format are null.
103105 * @throws IOException
104106 * If an I/O error occurs
105107 */
106108 public static CSVParser parse (File file , final CSVFormat format ) throws IOException {
109+ Assertions .notNull (file , "file" );
110+ Assertions .notNull (format , "format" );
111+
107112 return new CSVParser (new FileReader (file ), format );
108113 }
109114
110115 /**
111116 * Creates a parser for the given {@link String}.
112117 *
113118 * @param string
114- * a CSV string
119+ * a CSV string. Must not be null.
115120 * @param format
116- * the CSVFormat used for CSV parsing
121+ * the CSVFormat used for CSV parsing. Must not be null.
117122 * @return a new parser
123+ * @throws IllegalArgumentException
124+ * If the parameters of the format are inconsistent or if either string or format are null.
118125 * @throws IOException
119126 * If an I/O error occurs
120127 */
121128 public static CSVParser parse (String string , final CSVFormat format ) throws IOException {
129+ Assertions .notNull (string , "string" );
130+ Assertions .notNull (format , "format" );
131+
122132 return new CSVParser (new StringReader (string ), format );
123133 }
124134
@@ -131,17 +141,22 @@ public static CSVParser parse(String string, final CSVFormat format) throws IOEx
131141 * </p>
132142 *
133143 * @param url
134- * a URL
144+ * a URL. Must not be null.
135145 * @param charset
136146 * the charset for the resource, if {@code null}, uses {@code UTF-8}. UTF-8 is one of the encodings
137147 * required by the Java specification.
138148 * @param format
139- * the CSVFormat used for CSV parsing
149+ * the CSVFormat used for CSV parsing. Must not be null.
140150 * @return a new parser
151+ * @throws IllegalArgumentException
152+ * If the parameters of the format are inconsistent or if either url or format are null.
141153 * @throws IOException
142154 * If an I/O error occurs
143155 */
144156 public static CSVParser parse (URL url , Charset charset , final CSVFormat format ) throws IOException {
157+ Assertions .notNull (url , "url" );
158+ Assertions .notNull (format , "format" );
159+
145160 return new CSVParser (new InputStreamReader (url .openStream (),
146161 charset == null ? Charset .forName ("UTF-8" ) : charset ), format );
147162 }
@@ -169,15 +184,18 @@ public static CSVParser parse(URL url, Charset charset, final CSVFormat format)
169184 * </p>
170185 *
171186 * @param reader
172- * a Reader containing CSV-formatted input
187+ * a Reader containing CSV-formatted input. Must not be null.
173188 * @param format
174- * the CSVFormat used for CSV parsing
189+ * the CSVFormat used for CSV parsing. Must not be null.
175190 * @throws IllegalArgumentException
176- * thrown if the parameters of the format are inconsistent
191+ * If the parameters of the format are inconsistent or if either reader or format are null.
177192 * @throws IOException
178193 * If an I/O error occurs
179194 */
180195 public CSVParser (final Reader reader , final CSVFormat format ) throws IOException {
196+ Assertions .notNull (reader , "reader" );
197+ Assertions .notNull (format , "format" );
198+
181199 format .validate ();
182200 this .format = format ;
183201 this .lexer = new Lexer (format , new ExtendedBufferedReader (reader ));
0 commit comments