Skip to content

Commit

Permalink
[FLINK-17818] Fix argument check of CsvReader.pojoType()
Browse files Browse the repository at this point in the history
  • Loading branch information
damjad authored and aljoscha committed Sep 29, 2020
1 parent 81598d4 commit 6669ae0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public CsvReader ignoreInvalidLines(){
*/
public <T> DataSource<T> pojoType(Class<T> pojoType, String... pojoFields) {
Preconditions.checkNotNull(pojoType, "The POJO type class must not be null.");
Preconditions.checkNotNull(pojoFields, "POJO fields must be specified (not null) if output type is a POJO.");
Preconditions.checkArgument(pojoFields != null && pojoFields.length > 0, "POJO fields must be specified (not null) if output type is a POJO.");

final TypeInformation<T> ti = TypeExtractor.createTypeInfo(pojoType);
if (!(ti instanceof PojoTypeInfo)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,21 @@ public void testPOJOTypeWithFieldsOrder() throws Exception {
compareResultAsText(result, expected);
}

@Test(expected = NullPointerException.class)
@Test(expected = IllegalArgumentException.class)
public void testPOJOTypeWithoutFieldsOrder() throws Exception {
final String inputData = "";
final String dataPath = createInputData(inputData);
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

env.readCsvFile(dataPath).pojoType(POJOItem.class);
}

@Test(expected = IllegalArgumentException.class)
public void testPOJOTypeWitNullFieldsOrder() throws Exception {
final String inputData = "";
final String dataPath = createInputData(inputData);
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

env.readCsvFile(dataPath).pojoType(POJOItem.class, null);
}

Expand Down

0 comments on commit 6669ae0

Please sign in to comment.