powered by Jive Software

Conflicting code in FormFieldRegistry

In Smack 4.4.1 the register function in the FormFieldRegistry has some conflicting code.

If a registered field is already registered with a different fieldType a empty IllegalArgumentException is thrown, where as the intention of the code indicates it would be expected to log just a warning.

Solution: remove the throw of the IllegalArgumentException and the code alongside.

        FormField.Type previousType;
        synchronized (REGISTRY) {
            Map<String, FormField.Type> fieldNameToType = REGISTRY.get(formType);
            if (fieldNameToType == null) {
                fieldNameToType = new HashMap<>();
                REGISTRY.put(formType, fieldNameToType);
            } else {
//                previousType = fieldNameToType.get(fieldName);
//                if (previousType != null && previousType != fieldType) {
//                    throw new IllegalArgumentException();
//                }
            }
            previousType = fieldNameToType.put(fieldName, fieldType);
        }
        if (previousType != null && fieldType != previousType) {
            LOGGER.warning("Form field registry inconsitency detected: Registered field '" + fieldName + "' of type " + fieldType + " but previous type was " + previousType);
        }

This should be fine in 4.4.2, as this code path then only taken if a field is registered with a form type. And something is wrong if you want to register a different field type for the same (form field type, field name) tuple.