jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1100286 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
Date Fri, 06 May 2011 17:08:17 GMT
Author: jukka
Date: Fri May  6 17:08:17 2011
New Revision: 1100286

URL: http://svn.apache.org/viewvc?rev=1100286&view=rev
Log:
JCR-2960: Long values not properly stored

Avoid long overflow when deserializing values with more than 62 bits.
Add tests.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java?rev=1100286&r1=1100285&r2=1100286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
Fri May  6 17:08:17 2011
@@ -549,8 +549,13 @@ class BundleReader {
         long b;
         do {
             b = in.readUnsignedByte();
-            value = (b & 0x7f) << 57 | value >>> 7;
-            bits += 7;
+            if (bits < 57) {
+                value = (b & 0x7f) << 57 | value >>> 7;
+                bits += 7;
+            } else {
+                value = (b & 0x01) << 63 | value >>> 1;
+                bits = 64;
+            }
         } while ((b & 0x80) != 0);
         value = value >>> (64 - bits);
         if ((value & 1) != 0) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java?rev=1100286&r1=1100285&r2=1100286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
Fri May  6 17:08:17 2011
@@ -311,6 +311,37 @@ public class BundleBindingTest extends T
         assertBundleRoundtrip(bundle);
     }
 
+    public void testBooleanSerialization() throws Exception {
+        assertValueSerialization(InternalValue.create(true));
+        assertValueSerialization(InternalValue.create(false));
+    }
+
+    /**
+     * Tests serialization of long values.
+     */
+    public void testLongSerialization() throws Exception {
+        assertValueSerialization(InternalValue.create(0));
+        assertValueSerialization(InternalValue.create(1));
+        assertValueSerialization(InternalValue.create(-1));
+        assertValueSerialization(InternalValue.create(1234567890));
+        assertValueSerialization(InternalValue.create(-1234567890));
+        assertValueSerialization(InternalValue.create(Long.MAX_VALUE));
+        assertValueSerialization(InternalValue.create(Long.MIN_VALUE));
+    }
+
+    public void testDoubleSerialization() throws Exception {
+        assertValueSerialization(InternalValue.create(0.0));
+        assertValueSerialization(InternalValue.create(1.0));
+        assertValueSerialization(InternalValue.create(-1.0));
+        assertValueSerialization(InternalValue.create(12345.6789));
+        assertValueSerialization(InternalValue.create(-12345.6789));
+        assertValueSerialization(InternalValue.create(Double.MAX_VALUE));
+        assertValueSerialization(InternalValue.create(Double.MIN_VALUE));
+        assertValueSerialization(InternalValue.create(Double.POSITIVE_INFINITY));
+        assertValueSerialization(InternalValue.create(Double.NEGATIVE_INFINITY));
+        assertValueSerialization(InternalValue.create(Double.NaN));
+    }
+
     /**
      * Tests serialization of date values.
      */



Mime
View raw message