From 756690b250613099a006f69140fbaf3531e2c993 Mon Sep 17 00:00:00 2001 From: "joseph.smith" Date: Wed, 13 Jun 2018 10:39:58 -0500 Subject: [PATCH] HADOOP-15524 Bounding array size to Integer.MAX_VALUE - 8 to prevent OutOfMemoryError from occurring. --- .../src/main/java/org/apache/hadoop/io/BytesWritable.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BytesWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BytesWritable.java index 7d7b75ba05a00..b82e23cd94df2 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BytesWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BytesWritable.java @@ -35,6 +35,7 @@ @InterfaceStability.Stable public class BytesWritable extends BinaryComparable implements WritableComparable { + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; private static final int LENGTH_BYTES = 4; private static final byte[] EMPTY_BYTES = {}; @@ -121,7 +122,7 @@ public int getSize() { public void setSize(int size) { if (size > getCapacity()) { // Avoid overflowing the int too early by casting to a long. - long newSize = Math.min(Integer.MAX_VALUE, (3L * size) / 2L); + long newSize = Math.min(MAX_ARRAY_SIZE, (3L * size) / 2L); setCapacity((int) newSize); } this.size = size;