Skip to content

Commit fbce08d

Browse files
vkorukantisiddharthteotia
authored andcommitted
ARROW-2511: [Java] Fix BaseVariableWidthVector.allocateNew to not swallow exception (#1947)
+ Also remove the e.printStackTrace() calls
1 parent 6bf1c66 commit fbce08d

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ public boolean allocateNewSafe() {
281281
try {
282282
allocateBytes(curAllocationSizeValue, curAllocationSizeValidity);
283283
} catch (Exception e) {
284-
e.printStackTrace();
285284
clear();
286285
return false;
287286
}
@@ -314,7 +313,6 @@ public void allocateNew(int valueCount) {
314313
try {
315314
allocateBytes(valueBufferSize, validityBufferSize);
316315
} catch (Exception e) {
317-
e.printStackTrace();
318316
clear();
319317
throw e;
320318
}
@@ -841,4 +839,4 @@ protected void handleSafe(int index) {
841839
reAlloc();
842840
}
843841
}
844-
}
842+
}

java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ public boolean allocateNewSafe() {
394394
try {
395395
allocateBytes(curAllocationSizeValue, curAllocationSizeValidity, curAllocationSizeOffset);
396396
} catch (Exception e) {
397-
e.printStackTrace();
398397
clear();
399398
return false;
400399
}
@@ -427,8 +426,8 @@ public void allocateNew(int totalBytes, int valueCount) {
427426
try {
428427
allocateBytes(totalBytes, validityBufferSize, offsetBufferSize);
429428
} catch (Exception e) {
430-
e.printStackTrace();
431429
clear();
430+
throw e;
432431
}
433432
}
434433

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.arrow.vector;
19+
20+
import org.apache.arrow.memory.BufferAllocator;
21+
import org.apache.arrow.memory.OutOfMemoryException;
22+
import org.apache.arrow.memory.RootAllocator;
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
27+
/**
28+
* This class tests cases where we expect to receive {@link OutOfMemoryException}.
29+
*/
30+
public class TestOutOfMemoryForValueVector {
31+
32+
private final static String EMPTY_SCHEMA_PATH = "";
33+
34+
private BufferAllocator allocator;
35+
36+
@Before
37+
public void init() {
38+
allocator = new RootAllocator(200); // Start with low memory limit
39+
}
40+
41+
@Test(expected = OutOfMemoryException.class)
42+
public void variableWidthVectorAllocateNew() {
43+
try (VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator)) {
44+
vector.allocateNew();
45+
}
46+
}
47+
48+
@Test(expected = OutOfMemoryException.class)
49+
public void variableWidthVectorAllocateNewCustom() {
50+
try (VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator)) {
51+
vector.allocateNew(2342, 234);
52+
}
53+
}
54+
55+
@Test(expected = OutOfMemoryException.class)
56+
public void fixedWidthVectorAllocateNew() {
57+
try (IntVector vector = new IntVector(EMPTY_SCHEMA_PATH, allocator)) {
58+
vector.allocateNew();
59+
}
60+
}
61+
62+
@Test(expected = OutOfMemoryException.class)
63+
public void fixedWidthVectorAllocateNewCustom() {
64+
try (IntVector vector = new IntVector(EMPTY_SCHEMA_PATH, allocator)) {
65+
vector.allocateNew(2342);
66+
}
67+
}
68+
69+
@After
70+
public void terminate() {
71+
allocator.close();
72+
}
73+
}

0 commit comments

Comments
 (0)