Simplify if statement in ArraysSupport::hugeLength

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Not an Issue
    • Priority: P4
    • 23
    • Affects Version/s: 21, 22
    • Component/s: 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);
               }
           }

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

              Created:
              Updated:
              Resolved: