NIFI-3186: Fixed NPE that was overlooked

This closes #1317.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Mark Payne 2016-12-12 08:25:51 -05:00 committed by Bryan Bende
parent 5776c4b1f9
commit ab2d07aa5a
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
2 changed files with 29 additions and 0 deletions

View File

@ -73,6 +73,9 @@ public class ByteArraySchemaRecordReader extends CompressableRecordReader {
final InputStream limitedIn = new LimitingInputStream(in, recordLength); final InputStream limitedIn = new LimitingInputStream(in, recordLength);
final Record eventRecord = recordReader.readRecord(limitedIn); final Record eventRecord = recordReader.readRecord(limitedIn);
if (eventRecord == null) {
return null;
}
return EventRecord.getEvent(eventRecord, getFilename(), byteOffset, getMaxAttributeLength()); return EventRecord.getEvent(eventRecord, getFilename(), byteOffset, getMaxAttributeLength());
} }

View File

@ -20,6 +20,7 @@ package org.apache.nifi.provenance;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -164,6 +165,31 @@ public class TestSchemaRecordReaderWriter extends AbstractTestRecordReaderWriter
} }
} }
@Test
public void testAddOneRecordReadTwice() throws IOException {
final RecordField unitTestField = new SimpleRecordField("Unit Test Field", FieldType.STRING, Repetition.EXACTLY_ONE);
final Consumer<List<RecordField>> schemaModifier = fields -> fields.add(unitTestField);
final Map<RecordField, Object> toAdd = new HashMap<>();
toAdd.put(unitTestField, "hello");
try (final ByteArraySchemaRecordWriter writer = createSchemaWriter(schemaModifier, toAdd)) {
writer.writeHeader(1L);
writer.writeRecord(createEvent(), 3L);
}
try (final InputStream in = new FileInputStream(journalFile);
final TocReader tocReader = new StandardTocReader(tocFile);
final RecordReader reader = createReader(in, journalFile.getName(), tocReader, 10000)) {
final ProvenanceEventRecord firstEvent = reader.nextRecord();
assertNotNull(firstEvent);
final ProvenanceEventRecord secondEvent = reader.nextRecord();
assertNull(secondEvent);
}
}
/** /**
* Creates a SchemaRecordWriter that uses a modified schema * Creates a SchemaRecordWriter that uses a modified schema