Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321637

Simplify if statement in ArraysSupport::hugeLength

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 23
    • 21, 22
    • core-libs

      The else-if and else clauses in method ArraysSupport::hugeLength could be simplified by Math::max.

      diff --git a/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
      index 61be28519fc..09fb974c254 100644
      --- a/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
      +++ b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
      @@ -751,10 +751,8 @@ private static int hugeLength(int oldLength, int minGrowth) {
               if (minLength < 0) { // overflow
                   throw new OutOfMemoryError(
                       "Required array length " + oldLength + " + " + minGrowth + " is too large");
      - } else if (minLength <= SOFT_MAX_ARRAY_LENGTH) {
      - return SOFT_MAX_ARRAY_LENGTH;
      - } else {
      - return minLength;
      + } else {
      + return Math.max(minLength, SOFT_MAX_ARRAY_LENGTH);
               }
           }

            jjiang John Jiang
            jjiang John Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: