From 3fc8c3b1b799457c2432adb29c6cb2065306027e Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 1 Jul 2011 16:29:04 +0000 Subject: [PATCH] Apply patch from bug #51458 - Correct BitField wrapping when setting large values git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1141977 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + src/java/org/apache/poi/util/BitField.java | 2 +- src/testcases/org/apache/poi/util/TestBitField.java | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 293ba59dc9..977491cce2 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51458 - Correct BitField wrapping when setting large values 51460 - Improve HSSF performance when loading very long rows, by switching the CellValue array to an iterator 51444 - Prevent corrupted output when saving files created by LibreOffice 3.3 51422 - Support using RecalcIdRecord to trigger a full formula recalculation on load diff --git a/src/java/org/apache/poi/util/BitField.java b/src/java/org/apache/poi/util/BitField.java index 70d8f22081..f171145b4e 100644 --- a/src/java/org/apache/poi/util/BitField.java +++ b/src/java/org/apache/poi/util/BitField.java @@ -71,7 +71,7 @@ public class BitField public int getValue(final int holder) { - return getRawValue(holder) >> _shift_count; + return getRawValue(holder) >>> _shift_count; } /** diff --git a/src/testcases/org/apache/poi/util/TestBitField.java b/src/testcases/org/apache/poi/util/TestBitField.java index ef55ab7451..a5c953a435 100644 --- a/src/testcases/org/apache/poi/util/TestBitField.java +++ b/src/testcases/org/apache/poi/util/TestBitField.java @@ -188,4 +188,13 @@ public final class TestBitField extends TestCase { assertEquals(bf_single.clearShort(( short ) -1), bf_single.setShortBoolean(( short ) -1, false)); } + + public void testSetLargeValues() { + final BitField bf1 = new BitField(0xF), bf2 = new BitField(0xF0000000); + int a = 0; + a = bf1.setValue(a, 9); + a = bf2.setValue(a, 9); + assertEquals(9, bf1.getValue(a)); + assertEquals(9, bf2.getValue(a)); + } } -- 2.39.5