zhangkre commented on issue #1234:
URL: https://github.com/apache/arrow-java/issues/1234#issuecomment-5010380150
fixed code
```java
public ArrowRecordBatch getRecordBatch() {
List<ArrowFieldNode> nodes = new ArrayList<>();
List<ArrowBuf> buffers = new ArrayList<>();
List<Long> variadicBufferCounts = new ArrayList<>();
try {
for (FieldVector vector : root.getFieldVectors()) {
appendNodes(vector, nodes, buffers, variadicBufferCounts);
}
return new ArrowRecordBatch(
root.getRowCount(),
nodes,
buffers,
CompressionUtil.createBodyCompression(codec),
variadicBufferCounts,
alignBuffers,
false);
} catch (RuntimeException e) {
RuntimeException releaseException = releaseBuffers(buffers);
if (releaseException != null) {
e.addSuppressed(releaseException);
}
throw e;
}
}
private RuntimeException releaseBuffers(List<ArrowBuf> buffers) {
RuntimeException firstException = null;
for (ArrowBuf buf : buffers) {
try {
buf.getReferenceManager().release();
} catch (RuntimeException e) {
if (firstException == null) {
firstException = e;
} else {
firstException.addSuppressed(e);
}
}
}
return firstException;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]