DonalEvans commented on a change in pull request #6765:
URL: https://github.com/apache/geode/pull/6765#discussion_r692377660



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/netty/Coder.java
##########
@@ -332,9 +343,55 @@ public static BigDecimal bytesToBigDecimal(byte[] bytes) {
   }
 
   public static long bytesToLong(byte[] bytes) {
-    return Long.parseLong(bytesToString(bytes));
+    return parseLong(bytes);
+  }
+
+  private static NumberFormatException createNumberFormatException(byte[] 
bytes) {
+    return new NumberFormatException("For input string: \"" + 
bytesToString(bytes) + "\"");
+  }
+
+  /**
+   * This method was derived from openjdk Long.java parseLong
+   */
+  public static long parseLong(byte[] bytes) throws NumberFormatException {
+    final int len = bytes.length;
+    if (len <= 0) {
+      throw createNumberFormatException(bytes);
+    }
+    int i = 0;
+    long limit = -Long.MAX_VALUE;
+    boolean negative = false;
+    byte firstByte = bytes[0];
+    if (firstByte < NUMBER_0_BYTE) { // Possible leading "+" or "-"
+      if (firstByte == bMINUS) {
+        negative = true;
+        limit = Long.MIN_VALUE;
+      } else if (firstByte != bPLUS) {

Review comment:
       If we want to match Redis' behaviour exactly, we should also throw an 
exception if we're given a number that starts with "+" or with "-0". These 
could be done as separate tickets though, if you feel it's not worth including 
them here. In fact, we already have 
[GEODE-9482](https://issues.apache.org/jira/browse/GEODE-9482) to track the 
second case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to