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

Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • 17, 21, 22, 23
    • core-libs

      In `Method` and `Constructor`, we have two methods that clone the relevant arrays before returning them to external code:

          /**
           * {@inheritDoc}
           */
          @Override
          public Class<?>[] getParameterTypes() {
              return parameterTypes.clone();
          }

          /**
           * {@inheritDoc}
           */
          @Override
          public Class<?>[] getExceptionTypes() {
              return exceptionTypes.clone();
          }

      Frequently, those are empty arrays, and we do not really need to clone them. Note that JDK-8177107 did a related thing in shared parts: it would effectively populate these fields with a singleton empty class array.

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: