Skip to content

Commit b74fb36

Browse files
author
Sital Kedia
committed
Make close function call synchronized and address other review comments
1 parent 439cead commit b74fb36

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

core/src/main/java/org/apache/spark/io/NioBufferedFileInputStream.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ public synchronized int read() throws IOException {
8383

8484
@Override
8585
public synchronized int read(byte[] b, int offset, int len) throws IOException {
86-
if (!refill()) {
87-
return -1;
88-
}
8986
if ((offset | len | (offset + len) | (b.length - (offset + len))) < 0) {
9087
throw new IndexOutOfBoundsException();
91-
} else if (len == 0) {
92-
return 0;
88+
}
89+
if (!refill()) {
90+
return -1;
9391
}
9492
len = Math.min(len, byteBuffer.remaining());
9593
byteBuffer.get(b, offset, len);
@@ -132,8 +130,13 @@ private long skipFromFileChannel(long n) throws IOException {
132130
}
133131

134132
@Override
135-
public void close() throws IOException {
133+
public synchronized void close() throws IOException {
136134
fileChannel.close();
137135
StorageUtils.dispose(byteBuffer);
138136
}
137+
138+
@Override
139+
protected void finalize() throws IOException {
140+
close();
141+
}
139142
}

0 commit comments

Comments
 (0)