Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-8014

Using JNDI datasource throws NullPointerException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Blocker
    • 4.1.3, 4.2-milestone-1
    • 4.1
    • Old Core
    • Linux x86_64, OpenJDK 1.7, Windows Server 2008 R2, WAS 8.0
    • Unknown
    • N/A
    • N/A

    Description

      If connection.url property is not set in hibernate.cfg.xml a NullPointerException is thrown by com.xpn.xwiki.store.hibernate.DefaultHibernateSessionFactory.replaceVariables:

      Source:
      ...
      155 private void replaceVariables(Configuration hibernateConfiguration)
      156 {
      157 String url = hibernateConfiguration.getProperty(Environment.URL);
      158
      159 // Replace variables
      160 if (url.matches(".*\\$

      {.*\\}.*")) {
      ...


      Stack trace:

      java.lang.NullPointerException
      at com.xpn.xwiki.store.hibernate.DefaultHibernateSessionFactory$1.replaceVariables(DefaultHibernateSessionFactory.java:160)
      at com.xpn.xwiki.store.hibernate.DefaultHibernateSessionFactory$1.configure(DefaultHibernateSessionFactory.java:105)
      at com.xpn.xwiki.store.XWikiHibernateBaseStore.initHibernate(XWikiHibernateBaseStore.java:206)
      at com.xpn.xwiki.store.XWikiHibernateBaseStore.checkHibernate(XWikiHibernateBaseStore.java:589)
      at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:733)
      at com.xpn.xwiki.store.XWikiCacheStore.loadXWikiDoc(XWikiCacheStore.java:290)
      at com.xpn.xwiki.XWiki.getDocument(XWiki.java:1435)
      at com.xpn.xwiki.XWiki.getDocument(XWiki.java:1478)
      at com.xpn.xwiki.XWiki.getPrefsClass(XWiki.java:3141)
      at com.xpn.xwiki.XWiki.initializeMandatoryClasses(XWiki.java:822)
      at com.xpn.xwiki.XWiki.initXWiki(XWiki.java:793)
      at com.xpn.xwiki.XWiki.<init>(XWiki.java:734)
      ...




      Workaround:

      hibernate.cfg.xml:

      <property name="connection.url">foo</property>

      Suggested fix:

      ..
      private void replaceVariables(Configuration hibernateConfiguration)
      {
      String url = hibernateConfiguration.getProperty(Environment.URL);

      //Property may not be set when using a JNDI datasource
      if(url != null) {
      // Replace variables
      if (url.matches(".*\\$
      {.*\}

      .*")) {
      String newURL = StringUtils.replace(url, String.format("${%s}", PROPERTY_PERMANENTDIRECTORY),
      environment.getPermanentDirectory().getAbsolutePath());

      // Set the new URL
      hibernateConfiguration.setProperty(Environment.URL, newURL);
      logger.debug("Resolved Hibernate URL [{}] to [{}]", url, newURL);
      }
      }
      }

      ...

      Attachments

        Activity

          People

            sdumitriu Sergiu Dumitriu
            vdox vdox
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: