tags:

views:

330

answers:

2

Using Spring 1.2.1 and oracle.jdbc.pool.OracleDataSource 10.2.0.3.0 I sometimes get a stack trace like below. I think it is caused by the connection pool being full. Does anyone know the cause for sure? Also do newer versions of spring or Oracle JDBC handle this better?

java.lang.NullPointerException
    at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:213)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:444)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:491)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:522)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:543)
    at org.springframework.jdbc.object.SqlQuery.execute(SqlQuery.java:114)
    at org.springframework.jdbc.object.SqlQuery.execute(SqlQuery.java:124)
    at sps.wfds.biz.glacier.MemberDAO.create(MemberDAO.java:44)
    at sps.wfds.biz.glacier.MemberDAO.create(MemberDAO.java:23)
    at sps.wfds.biz.glacier.AbstractDAO.createAndValidate(AbstractDAO.java:22)
    at sps.wfds.web.interceptor.AbstractPrincipal.init(AbstractPrincipal.java:87)
    at sps.wfds.web.interceptor.AbstractPrincipal.getAttributes(AbstractPrincipal.java:66)
    at sps.wfds.web.interceptor.AbstractPrincipal.getAttribute(AbstractPrincipal.java:60)
    at sps.wfds.web.interceptor.AbstractPrincipal.setLocale(AbstractPrincipal.java:38)
    at sps.wfds.web.util.LocaleUtil.setLocale(LocaleUtil.java:24)
    at sps.wfds.web.interceptor.SSOPrincipal.(SSOPrincipal.java:22)
    at sps.wfds.web.interceptor.SSOAuthority.getPrincipal(SSOAuthority.java:18)
    at sps.wfds.web.interceptor.Authorization.preHandle(Authorization.java:44)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:674)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
    at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
+1  A: 

This has nothing to do with Spring.

DataSource.getConnection() should never return null; it should either return a valid connection or throw a SQLException. The error is caused by oracle.jdbc.pool.OracleDataSource misbehaving.

Update:

According to Oracke documentation this happens when:

  • the maximum number of connections has already been allocated in pool;
  • ConnectionWaitTimeout has been set to non-zero value
  • you've been waiting on getConnection() for that duration and no connections have been returned to the pool.

So with that in mind, you can:

  1. Review your code to make sure there's no connection leak
  2. Increase your pool size
  3. Increase your connection wait timeout
  4. Use a different pool :-) or write a simple wrapper around OracleDataSource that would check for 'null' being returned and throw an SqlException instead.

In that last scenario you'd only be trading one exception for the other, though (NPE -> SqlException). Granted, it'll be more appropriate but it's not really going to solve the problem.

ChssPly76
Thank you for providing the cause -- are you able to help with the cause of that?
James A. N. Stauffer
A: 
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

As you can see the signature takes a Connection object like ChssPly76 said and can't find it.

non sequitor
Based on the signature, how can you tell that the NullPointerException is caused by the method parameter instead of something else in the method?
James A. N. Stauffer