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

URL Parsing Bug

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Invalid
    • None
    • 1.3
    • None
    • Tomcat DBCP

    Description

      Hello,

      I think there's a bug at the org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory at the time of parsing a certain MySQL url. When the connection url contains the "sessionVariables" property alone, everything works ok. However, when other properties are specified in addition to "sessionVariables", then an Exception is thrown when trying to establish a new connection. If the same url is specified using a Connection object inside my code, then NO error is thrown. It only happens when that same url is set at the Resource config of the server.xml file. I include some examples to reproduce the error:

      Everything goes fine when this is the config of the resource (note that the important part is the url):

      <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
      factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
      maxActive="15"
      maxIdle="5"
      validationQuery="SELECT 1"
      testOnBorrow="false"
      testWhileIdle="true"
      timeBetweenEvictionRunsMillis="10000"
      minEvictableIdleTimeMillis="60000"
      username="user"
      password="pass"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3316/db?sessionVariables=@date='0',@version='1.0';"
      />

      However, if we set this other url in the previous example, an error will be printed on the tomcat's log file:

      jdbc:mysql://localhost:3316/db?transformedBitIsBoolean=true&sessionVariables=@date='0',@version='1.0';

      It seems to be a bug when sessionVariables is specified in addition to other
      properties, like transformedBitIsBoolean in the previous example.

      As I mentioned above, when this same url is set using a Connection object inside my application, no Exception is thrown, so I think the bug is located at the BasicDataSourceFactory class.

      This is the exception thrown:

      org.xml.sax.SAXParseException: The reference to entity "sessionVariables" must end with the ';' delimiter.
      at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
      at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
      at org.apache.xerces.impl.XMLScanner.scanAttributeValue(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanAttribute(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
      at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
      at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
      at org.apache.catalina.startup.Catalina.load(Catalina.java:489)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:543)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)

      This is the code I've used to test the same URL, but establishing a new Connection object inside my application:

      Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3316/db?transformedBitIsBoolean=true&sessionVariables=@date='0',@version='1.0';");

      As you can see, the URL is the same in both cases. However, now that I'm looking at the Exception in detail, the bug seems to be at the org.apache.tomcat.util.digester.Digester.parse method and not in the DBCP. Sorry if that's the case.

      Attachments

        Activity

          People

            Unassigned Unassigned
            hander3@terra.com R
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: