java.lang.NullPointerException

Spring JIRA | ismail altuntas | 4 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    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

    Spring JIRA | 4 years ago | ismail altuntas
    java.lang.NullPointerException
  2. 0

    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

    Spring JIRA | 4 years ago | ismail altuntas
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement()
    2. Spring Framework
      JdbcTemplate.query
      1. org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1375)
      2. org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580)
      3. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
      4. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
      5. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685)
      6. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693)
      6 frames