You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/08/01 21:41:11 UTC
svn commit: r1509395 - in /commons/proper/csv/trunk/src:
main/java/org/apache/commons/csv/CSVParser.java
test/java/org/apache/commons/csv/CSVParserTest.java
Author: britter
Date: Thu Aug 1 19:41:10 2013
New Revision: 1509395
URL: http://svn.apache.org/r1509395
Log:
Better throw a NoSuchElementException if no more elements are available because parser has been closed
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java?rev=1509395&r1=1509394&r2=1509395&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java Thu Aug 1 19:41:10 2013
@@ -381,8 +381,12 @@ public class CSVParser implements Iterab
}
/**
- * Returns an iterator on the records. IOExceptions occurring during the iteration are wrapped in a
+ * Returns an iterator on the records.
+ *
+ * <p>IOExceptions occurring during the iteration are wrapped in a
* RuntimeException.
+ * If the parser is closed a call to {@code next()} will throw a
+ * NoSuchElementException.</p>
*/
public Iterator<CSVRecord> iterator() {
return new Iterator<CSVRecord>() {
@@ -410,7 +414,7 @@ public class CSVParser implements Iterab
public CSVRecord next() {
if (CSVParser.this.isClosed()) {
- return null;
+ throw new NoSuchElementException("CSVParser has been closed");
}
CSVRecord next = this.current;
this.current = null;
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1509395&r1=1509394&r2=1509395&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Thu Aug 1 19:41:10 2013
@@ -394,7 +394,7 @@ public class CSVParserTest {
assertEquals(4, records.size());
}
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testClose() throws Exception {
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
final CSVParser parser = CSVFormat.DEFAULT.withCommentStart('#').withHeader().parse(in);
@@ -402,9 +402,7 @@ public class CSVParserTest {
assertTrue(records.hasNext());
parser.close();
assertFalse(records.hasNext());
- assertNull(records.next());
- assertFalse(records.hasNext());
- assertNull(records.next());
+ records.next();
}
@Test