You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2020/12/19 18:40:14 UTC

[cassandra] branch cassandra-3.0 updated: Avoid decimal-serializer.toString() creating huge string

This is an automated email from the ASF dual-hosted git repository.

jasonstack pushed a commit to branch cassandra-3.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-3.0 by this push:
     new a2aa78d  Avoid decimal-serializer.toString() creating huge string
a2aa78d is described below

commit a2aa78d7f4997be515c8e3d9a9795dc88a21c5d7
Author: Zhao Yang <zh...@gmail.com>
AuthorDate: Mon Dec 10 14:48:55 2018 +0800

    Avoid decimal-serializer.toString() creating huge string
    
    patch by Zhao Yang; reviewed by Benjamin Lerer for CASSANDRA-14925
---
 CHANGES.txt                                        |  1 +
 .../cassandra/serializers/DecimalSerializer.java   |  2 +-
 .../serializers/DecimalSerializerTest.java         | 51 ++++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index d560d91..53883bc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.24:
+ * Fix DecimalDeserializer#toString OOM (CASSANDRA-14925)
  * Extend the exclusion of replica filtering protection to other indices instead of just SASI (CASSANDRA-16311)
  * Synchronize transaction logs for JBOD (CASSANDRA-16225)
  * Fix the counting of cells per partition (CASSANDRA-16259)
diff --git a/src/java/org/apache/cassandra/serializers/DecimalSerializer.java b/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
index 819789f..e7e178b 100644
--- a/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
@@ -67,7 +67,7 @@ public class DecimalSerializer implements TypeSerializer<BigDecimal>
 
     public String toString(BigDecimal value)
     {
-        return value == null ? "" : value.toPlainString();
+        return value == null ? "" : value.toString();
     }
 
     public Class<BigDecimal> getType()
diff --git a/test/unit/org/apache/cassandra/serializers/DecimalSerializerTest.java b/test/unit/org/apache/cassandra/serializers/DecimalSerializerTest.java
new file mode 100644
index 0000000..83d30ce
--- /dev/null
+++ b/test/unit/org/apache/cassandra/serializers/DecimalSerializerTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cassandra.serializers;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigDecimal;
+
+public class DecimalSerializerTest
+{
+    @Test
+    public void testDecimalScaleStringify()
+    {
+        BigDecimal d = new BigDecimal("1");
+        assertEquals("1", DecimalSerializer.instance.toString(d));
+
+        d = new BigDecimal("-1");
+        assertEquals("-1", DecimalSerializer.instance.toString(d));
+
+        int scale = Integer.MAX_VALUE - 100;
+        d = new BigDecimal("1e" + scale);
+        assertEquals("1E+" + scale, DecimalSerializer.instance.toString(d));
+
+        d = new BigDecimal("-1e" + scale);
+        assertEquals("-1E+" + scale, DecimalSerializer.instance.toString(d));
+
+        d = new BigDecimal("1e-" + scale);
+        assertEquals("1E-" + scale, DecimalSerializer.instance.toString(d));
+
+        d = new BigDecimal("-1e-" + scale);
+        assertEquals("-1E-" + scale, DecimalSerializer.instance.toString(d));
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org