code: static Object[] getVarArgs(final Object[] args, final Class<?>[] methodParameterTypes) {
          if (args.length == methodParameterTypes.length
                  && args[args.length - 1].getClass().equals(methodParameterTypes[methodParameterTypes.length - 1])) {
              // The args array is already in the canonical form for the method.
              return args;
          }
  
          // Construct a new array matching the method's declared parameter types.
          final Object[] newArgs = new Object[methodParameterTypes.length];
  
          // Copy the normal (non-varargs) parameters
          System.arraycopy(args, 0, newArgs, 0, methodParameterTypes.length - 1);
  
          // Construct a new array for the variadic parameters
          final Class<?> varArgComponentType = methodParameterTypes[methodParameterTypes.length - 1].getComponentType();
          final int varArgLength = args.length - methodParameterTypes.length + 1;
  
          Object varArgsArray = Array.newInstance(ClassUtils.primitiveToWrapper(varArgComponentType), varArgLength);
          // Copy the variadic arguments into the varargs array.
          System.arraycopy(args, methodParameterTypes.length - 1, varArgsArray, 0, varArgLength);
  
          if(varArgComponentType.isPrimitive()) {
              // unbox from wrapper type to primitive type
              varArgsArray = ArrayUtils.toPrimitive(varArgsArray);
          }
  
          // Store the varargs array in the last position of the array to return
          newArgs[methodParameterTypes.length - 1] = varArgsArray;
  
          // Return the canonical varargs array.
          return newArgs;
      }
docs: <p>Given an arguments array passed to a varargs method, return an array of arguments in the canonical form,
  i.e. an array with the declared number of parameters, and whose last parameter is an array of the varargs type.
  </p>
  
  @param args the array of arguments passed to the varags method
  @param methodParameterTypes the declared array of method parameter types
  @return an array of the variadic arguments passed to the method
  @since 3.5