Uploaded image for project: 'Commons JCS'
  1. Commons JCS
  2. JCS-113

Potential NPE in JDBCDiskCache

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • jcs-2.0-beta-1
    • None
    • None

    Description

      The test JDBCDiskCacheManagerUnitTest fails with an NPE if debug logging is enabled.

      java.lang.NullPointerException
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCache.getSize(JDBCDiskCache.java:982)
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCache.getStatistics(JDBCDiskCache.java:1146)
      at org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache.getStats(AbstractDiskCache.java:525)
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCache.toString(JDBCDiskCache.java:1251)
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManagerAbstractTemplate.getCache(JDBCDiskCacheManagerAbstractTemplate.java:119)
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManager.getCache(JDBCDiskCacheManager.java:117)
      at org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManagerUnitTest.testGetCache_normal(JDBCDiskCacheManagerUnitTest.java:49)
      

      That happens because the getSize() method calls

      getPoolAccess().getConnection()
      

      and getPoolAccess() may return null if the initializePoolAccess method called by the constructor fails to set up the pool.

      It is trivial to check if the poolAccess field has been set up and avoid the NPE in getSize(). However, the getPoolAccess() method is used extensively within the class, and also externally as well.

      It looks as though the class is barely usable if the field cannot be initialised, so it might perhaps be better if the constructor threw an Exception of some kind.

      Attachments

        Activity

          People

            tv Thomas Vandahl
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: