Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-1364

Numerical properties of @DataSourceDefinition not correctly processed.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 8.0.0.Alpha2
    • None
    • EE
    • None

      When using the <data-source> element in e.g. web.xml or application.xml, numerical properties (such as <port-number>) are not processed correctly.

      With many data sources, e.g. the one from the Postgres JDBC driver, those properties are not set at all.

      The problem seems to be with org.jboss.as.connector.deployers.datasource.DirectDataSourceInjectionSource. In the method populateProperties those values are passed as an Integer:

      setProperty(
          deploymentReflectionIndex, dataSourceClass, properties, 
          PORT_NUMBER_PROP, Integer.valueOf(portNumber)
      );
      

      The type of this value is subsequently used to locate a setter method for the corresponding property from the data source:

      // [...]
      String methodName = builder.toString();
      Class<?> paramType = value.getClass();
      MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType);
      Method setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier);
      
      if (setterMethod != null) {
          properties.put(name, value.toString());
      }
      

      The problem is that many data source implementations have a setter that takes a primitive int, and not an Integer. There will thus be no setter method found that takes an Integer. This code will then skip the property.

      Down the line, when it's time to actually set the properties on the data source instance the code is written in such a way that the int/Integer distinction wouldn't matter anymore:

      XAManagedConnectionFactory#createXaDataSource

      Method getter = clazz.getMethod("get" + name, noClasses);
      type = getter.getReturnType();
      
      // [...]
      
      Method setter = clazz.getMethod("set" + name, new Class<?>[]{type});
      PropertyEditor editor = PropertyEditorManager.findEditor(type);
      
      // [..]
      
      editor.setAsText(value);
      setter.invoke(xads, new Object[]{editor.getValue()});
      

      However, at that point the numerical properties have already been removed from the properties collection because of the failing test shown above.

            sdouglas1@redhat.com Stuart Douglas
            arjan.tijms@gmail.com Arjan Tijms (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: