Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-473

Data source bean creation failed due to mismatched return type of setter and getter for connectionInitSqls in BasicDataSource

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.1.1
    • 2.12.0
    • Tomcat
      java 7 update 70
      spring 2.5

    • Important

    Description

      Description

      The issue is that while Spring Starts bean creation of datasource, It throws exception org.springframework.beans.NotWritablePropertyException. And complains that Invalid property 'connectionInitSqls' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property 'connectionInitSqls' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

      Steps To Reproduce

      Here is My bean configuration in Spring's XML config file.

      applicationContext-datasource.xml
      <bean id="fileStore_dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
      	destroy-method="close" lazy-init="true">
              <!-- Just that property which causes problem -->
      	<property name="connectionInitSqls">
      		<list>
      			<value>#{filestore.jdbc.connectionInitSql}</value>
      		</list>
      	</property>
      </bean>
      

      Here is the Code from DBCP2 version 2.1.1

      BasicDataSource.java
      private volatile List<String> connectionInitSqls;
      
          public List<String> getConnectionInitSqls() {
              final List<String> result = connectionInitSqls;
              if (result == null) {
                  return Collections.emptyList();
              }
              return result;
          }
      
          public void setConnectionInitSqls(final Collection<String> connectionInitSqls) {
              if (connectionInitSqls != null && connectionInitSqls.size() > 0) {
                  ArrayList<String> newVal = null;
                  for (final String s : connectionInitSqls) {
                  if (s != null && s.trim().length() > 0) {
                          if (newVal == null) {
                              newVal = new ArrayList<>();
                          }
                          newVal.add(s);
                      }
                  }
                  this.connectionInitSqls = newVal;
              } else {
                  this.connectionInitSqls = null;
              }
          }
      
      Improvements/sugestions

      There should be a new setter method for connectionInitSqls which accept List<E> Type argument.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mubasherusman Mubasher Usman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: