Jackrabbit Content Repository
  1. Jackrabbit Content Repository
  2. JCR-3288

ConnectionFactory.getDriverClass() should use Thread.currentThread().getContextClassLoader(); instead of Class.forName()

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 2.3.3
    • Fix Version/s: None
    • Component/s: jackrabbit-core
    • Labels:
      None
    • Environment:
      WXP Sun JDK 1.6.0_30 Derby database

      Description

      Hi

      The ConnectionFactory.getDriverClass() should use Thread.currentThread().getContextClassLoader(); instead of Class.forName() otherwise dynamically added jdbc drivers to the classpath are not found;

      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      return cl.loadClass(driver);
      // return Class.forName(driver);

        Activity

        Hide
        Justin Edelson added a comment - - edited

        Wouldn't ConnectionFactory.class.getClassLoader() be a better way of obtaining the correct classloader?

        Show
        Justin Edelson added a comment - - edited Wouldn't ConnectionFactory.class.getClassLoader() be a better way of obtaining the correct classloader?
        Hide
        Francis ANDRE added a comment -

        Hi

        This won't work if the ConnectionFactory class is loaded before the Thread..currentThread().setContextClassLoader() is called to change the curretn classloader.

        Show
        Francis ANDRE added a comment - Hi This won't work if the ConnectionFactory class is loaded before the Thread..currentThread().setContextClassLoader() is called to change the curretn classloader.
        Hide
        Jukka Zitting added a comment -

        We've had plenty of problems with using the context class loader especially in OSGi environments. Do you have specific deployment scenario where Jackrabbit fails because of this? I'd much rather fix that specific problem instead of messing around with class loading for everyone.

        Show
        Jukka Zitting added a comment - We've had plenty of problems with using the context class loader especially in OSGi environments. Do you have specific deployment scenario where Jackrabbit fails because of this? I'd much rather fix that specific problem instead of messing around with class loading for everyone.
        Hide
        Felix Meschberger added a comment - - edited

        Whatever the final solution, using Class.forName(String) is really problematic in OSGi scenarios since there is some hard reference kept in the system preventing the class from being (garbage) collected.

        So this call should be replaced in any case.

        See http://blog.bjhargrave.com/2007/07/why-do-classforname-and.html and http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html

        Show
        Felix Meschberger added a comment - - edited Whatever the final solution, using Class.forName(String) is really problematic in OSGi scenarios since there is some hard reference kept in the system preventing the class from being (garbage) collected. So this call should be replaced in any case. See http://blog.bjhargrave.com/2007/07/why-do-classforname-and.html and http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html
        Hide
        Francis ANDRE added a comment -

        The JCR is used in the Apache open source ERP OFBiz and the JDBC driver class jar is added dynamically to the classpath before calling the JCR ConnecctionFactory.

        Show
        Francis ANDRE added a comment - The JCR is used in the Apache open source ERP OFBiz and the JDBC driver class jar is added dynamically to the classpath before calling the JCR ConnecctionFactory.

          People

          • Assignee:
            Unassigned
            Reporter:
            Francis ANDRE
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development