Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-88

org.mariadb.jdbc.MySQLResultSet.getTimestamp(int, Calendar) throws NullPointerException if column is NULL

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.6, 1.1.7
    • 1.1.8
    • None
    • None

    Description

      Since getValueObject(columnIndex).getTimestamp(cal) may return null, the method can throw NullPointerException

      public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
          try {
              return new Timestamp(getValueObject(columnIndex).getTimestamp(cal).getTime());
          } catch (ParseException e) {
              throw SQLExceptionMapper.getSQLException("Could not parse timestamp",e);
          }
      }

      Easy fix is to check for null before attempting to call getTime()

      public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
          try {
          	Timestamp timestamp = getValueObject(columnIndex).getTimestamp(cal);
          	
              return timestamp == null ? null : new Timestamp(timestamp.getTime());
          } catch (ParseException e) {
              throw SQLExceptionMapper.getSQLException("Could not parse timestamp",e);
          }
      }

      Attachments

        Activity

          People

            massimo.siani Massimo Siani (Inactive)
            emattheis Erik Mattheis
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.