Factored out code to handle array parameter types.

@throws Exception with a message describing why the types are incompatible.
764569
private static Object tryToMakeCompatibleArray(
            final Class<?> expectedComponentClz,
            final Class<?> inputComponentClz,
            Object param)
    throws VoltTypeException
    {
        int inputLength = Array.getLength(param);

        if (inputComponentClz == expectedComponentClz) {
            return param;
        }
        // if it's an empty array, let it through
        // this is a bit ugly as it might hide passing
        //  arrays of the wrong type, but it "does the right thing"
        //  more often that not I guess...
        else if (inputLength == 0) {
            return Array.newInstance(expectedComponentClz, 0);
        }
        // hack to make strings work with input as bytes
        else if (isByteArrayClass(inputComponentClz)
                && (expectedComponentClz == String.class)) {
            String[] values = new String[inputLength];
            for (int i = 0; i < inputLength; i++) {
                try {
                    values[i] = new String((byte[]) Array.get(param, i), "UTF-8");
                } catch (UnsupportedEncodingException ex) {
                    throw new VoltTypeException(
                            "tryScalarMakeCompatible: Unsupported encoding:"
                            + expectedComponentClz.getName() + " to provided " + inputComponentClz.getName());
                }
            }
            return values;
        }
        // hack to make varbinary work with input as hex string
        else if ((inputComponentClz == String.class) &&
                (expectedComponentClz == byte[].class)) {
            byte[][] values = new byte[inputLength][];
            for (int i = 0; i < inputLength; i++) {
                values[i] = Encoder.hexDecode((String) Array.get(param, i));
            }
            return values;
        } else if ((inputComponentClz == String.class) &&
                (expectedComponentClz == Byte[].class)) {
            Byte[][] boxvalues = new Byte[inputLength][];
            for (int i = 0; i < inputLength; i++) {
                boxvalues[i] = ArrayUtils.toObject(
                        Encoder.hexDecode((String) Array.get(param, i)) );
            }
            return boxvalues;
        }
        else {
            /*
             * Arrays can be quite large so it doesn't make sense to silently do the conversion
             * and incur the performance hit. The client should serialize the correct invocation
             * parameters
             */
            throw new VoltTypeException(
                    "tryScalarMakeCompatible: Unable to match parameter array:"
                    + expectedComponentClz.getName() + " to provided " + inputComponentClz.getName());
        }
    }
246992
@SuppressWarnings("unchecked")
    static <T extends Type> T decodeStaticArray(
            String input, int offset, TypeReference<T> typeReference, int length) {

        BiFunction<List<T>, String, T> function = (elements, typeName) -> {
            if (elements.isEmpty()) {
                throw new UnsupportedOperationException("Zero length fixed array is invalid type");
            } else {
                return instantiateStaticArray(typeReference, elements, length);
            }
        };

        return decodeArrayElements(input, offset, typeReference, length, function);
    }
988324
@Override
    public void validate(String name, String value) throws ParameterException {
        if(!value.equals(ArbiterCliGenerator.REGRESSION) || value.equals(ArbiterCliGenerator.CLASSIFICIATION)) {
            throw new ParameterException("Problem type can only be " + ArbiterCliGenerator.REGRESSION + " or " + ArbiterCliGenerator.CLASSIFICIATION);

        }
    }
686214
protected void writeArrayOutParamsToProxy(VariableElement param, MethodSpec.Builder methodBuilder) {
        methodBuilder.beginControlFlow("if (" + param.getSimpleName() + " == null)");
        methodBuilder.addStatement("data.writeInt(-1)");
        methodBuilder.endControlFlow();
        methodBuilder.beginControlFlow("else");
        methodBuilder.addStatement("data.writeInt(" + param.getSimpleName() + ".length)");
        methodBuilder.endControlFlow();
    }
155305
private function _checkJoinArray()
	{
		$defaultJoinArray = array('way' => null, 'tables' => null, 'conditionType' => null, 'condition' => null);
		if($this->joinArray === $defaultJoinArray)
		{
			throw new \Exception('one of the methods: inner(), natural(), left[Outer](), right[Outer] must called before!');
		}
	}
668368
private void parseElement(final String elementName, final boolean inArray) throws Exception {
        JsonToken currentToken = jsonParser.getCurrentToken();
        if (inArray) {
            startElement(elementName);
        }
        if (START_OBJECT.equals(currentToken)) {
            parseObject();
        } else if (START_ARRAY.equals(currentToken)) {
            parseArray(elementName);
        } else if (currentToken.isScalarValue()) {
            parseValue();
        }
        if (inArray) {
            endElement(elementName);
        }
    }
1187978
@ObjectiveCName("appendArrayGenericType:types:")
    public static void appendArrayGenericType(StringBuilder out, Type[] types) {
        if (types.length == 0) {
            return;
        }
        appendGenericType(out, types[0]);
        for (int i = 1; i < types.length; i++) {
            out.append(',');
            appendGenericType(out, types[i]);
        }
    }
94509
private static String getExceptionMessage(final String[] exception) {
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < exception.length; i++) {
            buff.append(exception[i]);
        }
        return buff.toString();
    }
484784
private static int handleParametrizationException(ProgramParametrizationException e) {
		LOG.error("Program has not been parametrized properly.", e);
		System.err.println(e.getMessage());
		return 1;
	}
899422
void compareArrayTypes(Schema oldSchema,
                                                Schema newSchema,
                                                List<Message> messages,
                                                String name) {
        if(oldSchema == null || newSchema == null || oldSchema.getType() != Schema.Type.ARRAY) {
            throw new IllegalArgumentException("Old schema must be ARRAY type. Name=" + name
                                               + ". Type=" + oldSchema);
        }

        if(newSchema.getType() != Schema.Type.ARRAY) {
            messages.add(new Message(Level.ERROR, "Illegal type change from " + oldSchema.getType()
                                                  + " to " + newSchema.getType() + " for field "
                                                  + name));
            return;
        }

        // Compare the array element types
        compareTypes(oldSchema.getElementType(),
                     newSchema.getElementType(),
                     messages,
                     name + ".<array element>");
    }
1183326
public Type getTypeOfArrayItems()
      throws DataConversionException {
    JsonSchema arrayValues = getItemsWithinDataType();
    if (arrayValues == null) {
      throw new DataConversionException("Array types only allow values as primitive, null or JsonObject");
    }
    return arrayValues.getType();
  }
1312961
private void throwExStrParam(MethodVisitor mv, Class<?> exCls) {
		String exSig = Type.getInternalName(exCls);
		mv.visitTypeInsn(NEW, exSig);
		mv.visitInsn(DUP);
		mv.visitLdcInsn("mapping " + this.className + " failed to map field:");
		mv.visitVarInsn(ALOAD, 2);
		mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "concat", "(Ljava/lang/String;)Ljava/lang/String;");
		mv.visitMethodInsn(INVOKESPECIAL, exSig, "<init>", "(Ljava/lang/String;)V");
		mv.visitInsn(ATHROW);
	}
799094
protected function checkTypeAllowed()
    {
        if (!in_array($this->type, static::$ALLOWED_TYPES)) {
            throw new \Exception(
                sprintf(
                    "`%s` is not a valid environment type. Expected one of: %s",
                    $this->type,
                    implode(', ', static::$ALLOWED_TYPES)
                )
            );
        }
    }
1079327
def raise_invalid_type_exception(self):
        """"""
        message = 'Expecting element type of %s' % (
            self._parameter.element_type.__name__)
        err = ValueError(message)
        return err
381302
protected function validateConf()
    {
        foreach ($this->getRequiredConfParams() as $name => $type) {
            if (!isset($this->params[$name]) || gettype($this->params[$name]) !== $type) {
                throw new Exception("Parameter '{$name}' missing or not of type '{$type}' (adapter '{$this->name}')");
            }
            if (substr($name, -5) == '_path') {
                $path = $this->getConfParam($name);
                if (!is_file($path)) {
                    throw new Exception("File not found: $path");
                }
            }
        }
    }
191364
void parameter(Object value) {
        // TODO check on supported types?
        if (value instanceof Observable)
            throw new IllegalArgumentException(
                    "use parameters() method not the parameter() method for an Observable");
        parameters(Observable.just(value));
    }
971051
public final void mARRAY() throws RecognitionException {
        try {
            int _type = ARRAY;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // org/javaruntype/type/parser/Type.g:30:7: ( '[]' )
            // org/javaruntype/type/parser/Type.g:30:9: '[]'
            {
            match("[]"); 


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }