9 Replies Latest reply on Dec 6, 2004 7:54 PM by koreth

    NullPointerException in PreparedStatementCache.ageOut

    asafy

      I'm using jboss 3.2.2 and Mysql 4.0

      I'm receiving this Exception very frequently.

      is there a way to disable the PreparedStatementCache ?

      or did any one see this exception ?

      thanks

        • 1. Re: NullPointerException in PreparedStatementCache.ageOut
          efe

          Hi there,

          I also get this exception under 322 when activating the PreparedStatementCache on the DataSource (Oracle this time), but have no clue for now.

          Note:
          To disable the cache, remove the related xml tag from your datasource configuration or set the size to 0. Watch for OPEN_CURSORS if using Oracle though, or make sure apps do close all their Statement.


          Below is sample stacktrace (truncated):

          java.lang.NullPointerException
          at org.jboss.resource.adapter.jdbc.PreparedStatementCache.ageOut(PreparedStatementCache.java:30)
          at org.jboss.util.LRUCachePolicy$LRUList.demote(LRUCachePolicy.java:344)
          at org.jboss.util.LRUCachePolicy.insert(LRUCachePolicy.java:162)
          at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:341)
          at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:209)
          at com.[...].AbstractDAO.prepareStatement(AbstractDAO.java:1489)
          at com.[...].AbstractDAO.selectAll(AbstractDAO.java:1776)
          ...

          Any advice appreciated.

          Regards.

          • 2. Re: NullPointerException in PreparedStatementCache.ageOut
            rudivankeirsbilck

            I am experiencing this problem to. My app is using 40 entity beans of which 38 are using entity caching strategy A, the others are using B.
            The ones that are using the A-caching strategy also have read-only attributes for their getters.

            The NullPointerException occurs randomly for any of the 38 beans.

            The problems started when I added <prepared-statement-cache-size>50</prepared-statement-cache-size> to my datasource and went away when I removed that line, as suggested by the previous post.

            Could somebody, anybody explain why this is happening please. I have to put my app in production soon and had planned to do it with the prepared-statement-cache and am worried to death that the same problem will occur there ;-)

            Thank you.

            • 3. Re: NullPointerException in PreparedStatementCache.ageOut
              rudivankeirsbilck

              Forgot to mention the platform: Mac OS X 10.3.5 running on dual 2 GHz G5 with 1.5 GB RAM

              Collegues of mine are running on Windows XP (SP1) and are not having this problem.

              The db is mysql 4.0.16 and is running on the same machine.

              • 4. Re: NullPointerException in PreparedStatementCache.ageOut

                I started seeing the same problem under 4.0.1RC1 when I turned on the prepared statement cache. My OS is Solaris 9, JVM is Sun's 1.4.2_06 on a dual-processor SPARC server talking to an Oracle 8i database.

                So I guess we've established that it's not OS-specific, it's not database-specific, and it's not JBoss version-specific!

                The start of my stack trace:

                java.lang.NullPointerException
                at org.jboss.resource.adapter.jdbc.PreparedStatementCache.ageOut(PreparedStatementCache.java:37)
                at org.jboss.util.LRUCachePolicy$LRUList.demote(LRUCachePolicy.java:346)
                at org.jboss.util.LRUCachePolicy.insert(LRUCachePolicy.java:162)
                at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:350)
                at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:205)

                (The next stack element is my application code that's doing a JDBC prepareStatement() call.)

                Any ideas on this?

                • 5. Re: NullPointerException in PreparedStatementCache.ageOut

                  I'm still seeing this problem in 4.0.1RC2, which was just released (over a month after the bug in question was marked closed, so I assume it ought to include the fix.)

                  • 6. Re: NullPointerException in PreparedStatementCache.ageOut
                    starksm64

                    There was still an element of the fix missing from the 4.0 branch. It has been fixed for the 4.0.1 final release.

                    • 7. Re: NullPointerException in PreparedStatementCache.ageOut

                      No joy. I checked out the latest sources from CVS just now, and I still get the same exception:

                      java.lang.NullPointerException
                      at org.jboss.resource.adapter.jdbc.PreparedStatementCache.ageOut(PreparedStatementCache.java:37)
                      at org.jboss.util.LRUCachePolicy$LRUList.demote(LRUCachePolicy.java:346)
                      at org.jboss.util.LRUCachePolicy.insert(LRUCachePolicy.java:162)
                      at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:350)
                      at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:205)
                      ...

                      For good measure, I tried checking out both the "jboss-4.0" module and the "jboss-head" module; same result from both. Has this fix not hit CVS yet? If not, is there a patch I can apply?

                      • 8. Re: NullPointerException in PreparedStatementCache.ageOut
                        starksm64

                        You'll have to wait until the anonymous cvs repository synchs up as the source you have is not the latest. There is no code on line 37 than can cause an NPE any longer. The PreparedStatementCache needs to match:

                        [starksm@banshee9100 jdbc]$ grep -n . PreparedStatementCache.java
                        2:/*
                        3: * JBoss, the OpenSource J2EE webOS
                        4: *
                        5: * Distributable under LGPL license.
                        6: * See terms of license at gnu.org.
                        7: *
                        8: */
                        10:package org.jboss.resource.adapter.jdbc;
                        12:import org.jboss.util.LRUCachePolicy;
                        13:import org.jboss.logging.Logger;
                        15:import java.sql.SQLException;
                        16:import java.sql.PreparedStatement;
                        18:/**
                        19: * LRU cache for PreparedStatements. When ps ages out, close it.
                        20: *
                        21: * Created: Mon Aug 12 21:53:02 2002
                        22: *
                        23: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
                        24: * @version $Revision: 1.1.2.3 $
                        25: */
                        26:public class PreparedStatementCache extends LRUCachePolicy
                        27:{
                        29: private final Logger log = Logger.getLogger(getClass());
                        31: public PreparedStatementCache(int max)
                        32: {
                        33: super(2, max);
                        34: create();
                        35: }
                        37: protected void ageOut(LRUCachePolicy.LRUCacheEntry entry)
                        38: {
                        39: try
                        40: {
                        41: CachedPreparedStatement ws = (CachedPreparedStatement) entry.m_objec
                        t;
                        42: ws.agedOut();
                        43: }
                        44: catch (SQLException e)
                        45: {
                        46: log.error("Failed closing cached statement", e);
                        47: }
                        48: finally
                        49: {
                        50: super.ageOut(entry);
                        51: }
                        52: }
                        54:}
                        



                        • 9. Re: NullPointerException in PreparedStatementCache.ageOut

                          Thanks! That seems to have done the trick.