AbstractPropertyInvoker.convertSimpleType doesn't support Object forms of primitives

5 views
Skip to first unread message

kris....@overwatchid.com

unread,
Jun 13, 2018, 10:36:35 AM6/13/18
to ldaptive
AbstractPropertyInvoker.convertSimpleType doesn't support Object forms of primitives like Integer, Long, Boolean.

  protected Object convertSimpleType(final Class<?> type, final String value)

  {

    Object newValue = value;

    if (Class.class.isAssignableFrom(type)) {

      newValue = createTypeFromPropertyValue(Class.class, value);

    } else if (Class[].class.isAssignableFrom(type)) {

      newValue = createArrayTypeFromPropertyValue(Class.class, value);

    } else if (type.isEnum()) {

      newValue = getEnum(type, value);

    } else if (String[].class == type) {

      newValue = value.split(",");

    } else if (Object[].class == type) {

      newValue = value.split(",");

    } else if (float.class == type) {

      newValue = Float.parseFloat(value);

    } else if (int.class == type) {

      newValue = Integer.parseInt(value);

    } else if (long.class == type) {

      newValue = Long.parseLong(value);

    } else if (short.class == type) {

      newValue = Short.parseShort(value);

    } else if (double.class == type) {

      newValue = Double.parseDouble(value);

    } else if (boolean.class == type) {

      newValue = Boolean.valueOf(value);

    }

    return newValue;

  }


When attempting to configure a JAAS module to use GSSAPI you can't configure Boolean properties.

options.put("bindSaslConfig", "{{mechanism=GSSAPI}{mutualAuthentication=true}}");


Results in

Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.ldaptive.props.AbstractPropertyInvoker.invokeMethod(AbstractPropertyInvoker.java:462)



if we modify the converSimpleType method to have checks on the Object forms like so

else if (Boolean.class == type) {

        newValue = Boolean.valueOf(value);

     }

Then the property setters work as expected.

Daniel Fisher

unread,
Jun 18, 2018, 12:07:02 PM6/18/18
to ldap...@googlegroups.com
On Wed, Jun 13, 2018 at 10:36 AM <kris....@overwatchid.com> wrote:

if we modify the converSimpleType method to have checks on the Object forms like so

else if (Boolean.class == type) {

        newValue = Boolean.valueOf(value);

     }

Then the property setters work as expected.


Thank you for the analysis. I created: https://github.com/vt-middleware/ldaptive/issues/135 to track this change.

--Daniel Fisher
 
Reply all
Reply to author
Forward
0 new messages