public static void assignFieldParams(Object bean, Map<String, Param> params)
            throws TikaConfigException {
        Class<?> beanClass = bean.getClass();
        if (!PARAM_INFO.containsKey(beanClass)) {
            synchronized (TikaConfig.class) {
                if (!PARAM_INFO.containsKey(beanClass)) {
                    List<AccessibleObject> aObjs =
                            collectInfo(beanClass, org.apache.tika.config.Field.class);
                    List<ParamField> fields = new ArrayList<>(aObjs.size());

                    for (AccessibleObject aObj : aObjs) {
                        fields.add(new ParamField(aObj));
                    }
                    PARAM_INFO.put(beanClass, fields);
                }
            }
        }

        List<ParamField> fields = PARAM_INFO.get(beanClass);

        for (ParamField field : fields) {
            Param<?> param = params.get(field.getName());
            if (param != null) {
                if (field.getType().isAssignableFrom(param.getType())) {
                    try {
                        field.assignValue(bean, param.getValue());
                    } catch (InvocationTargetException e) {
                        LOG.error("Error assigning value '{}' to '{}'", param.getValue(), param.getName());
                        final Throwable cause = e.getCause() == null ? e : e.getCause();
                        throw new TikaConfigException(cause.getMessage(), cause);
                    } catch (IllegalAccessException e) {
                        LOG.error("Error assigning value '{}' to '{}'", param.getValue(), param.getName());
                        throw new TikaConfigException(e.getMessage(), e);
                    }
                } else {
                    String msg = String.format(Locale.ROOT,
                            "Value '%s' of type '%s' can't be" +
                                    " assigned to field '%s' of defined type '%s'",
                            param.getValue(),
                            param.getValue().getClass(), field.getName(), field.getType());
                    throw new TikaConfigException(msg);
                }
            } else if (field.isRequired()) {
                //param not supplied but field is declared as required?
                String msg = String.format(Locale.ROOT,
                        "Param %s is required for %s," + " but it is not given in config.",
                        field.getName(), bean.getClass().getName());
                throw new TikaConfigException(msg);
            } else {
                LOG.debug("Param not supplied, field is not mandatory");
            }
        }
    }
@Test
    public void testMisMatchType() {

        class MyParser extends Configurable {
            @Field(required = true)
            int config;
        }

        Map<String, Param> params = new HashMap<>();
        try {
            params.put("config", new Param<>("config", 1));

            MyParser bean = new MyParser();
            AnnotationUtils.assignFieldParams(bean, params);
            assertEquals(bean.config, 1);
        } catch (TikaConfigException e) {
            e.printStackTrace();
            fail("Exception Not expected");
        }

        params.clear();
        try {
            params.put("config", new Param<>("config", "a string value"));
            AnnotationUtils.assignFieldParams(new MyParser(), params);
            fail("Exception expected");
        } catch (TikaConfigException e) {
            //expected
        }
    }