java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I have a custom Datasource implementation that not throw any exception when there is no DB connection. I am using this Datasource implementation with JdbcTemplate.java utility and when there is no connection JdbcTemplate throwing a NullPointerExeption. see the stack trace: {code} java.lang.NullPointerException at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1375) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693) {code} I think DataSourceUtils.getConnection() method should check the connection if it is null and then throw CannotGetJdbcConnectionException exception. So that appplication should check a meaningfull exception to take an action in this case. Similarly to above case when a transactional operation exist following exception is occured. In this case also CannotGetJdbcConnectionException should be occured ; {code} org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.IllegalArgumentException: Connection must not be null at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127) {code} Thanks
    via by ismail altuntas,
  • I have a custom Datasource implementation that not throw any exception when there is no DB connection. I am using this Datasource implementation with JdbcTemplate.java utility and when there is no connection JdbcTemplate throwing a NullPointerExeption. see the stack trace: {code} java.lang.NullPointerException at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1375) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693) {code} I think DataSourceUtils.getConnection() method should check the connection if it is null and then throw CannotGetJdbcConnectionException exception. So that appplication should check a meaningfull exception to take an action in this case. Similarly to above case when a transactional operation exist following exception is occured. In this case also CannotGetJdbcConnectionException should be occured ; {code} org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.IllegalArgumentException: Connection must not be null at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127) {code} Thanks
    via by ismail altuntas,
    • java.lang.NullPointerException at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1375) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693)
    No Bugmate found.