mirror of https://github.com/apache/nifi.git
NIFI-3186: Fixed NPE that was overlooked
This closes #1317. Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
parent
5776c4b1f9
commit
ab2d07aa5a
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue