[CONJ-88] org.mariadb.jdbc.MySQLResultSet.getTimestamp(int, Calendar) throws NullPointerException if column is NULL Created: 2014-04-03  Updated: 2015-01-08  Resolved: 2014-06-19

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.6, 1.1.7
Fix Version/s: 1.1.8

Type: Bug Priority: Major
Reporter: Erik Mattheis Assignee: Massimo Siani (Inactive)
Resolution: Fixed Votes: 1
Labels: 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);
    }
}



 Comments   
Comment by Massimo Siani (Inactive) [ 2014-06-19 ]

Fixed in rev 510.

Comment by swathi marathi [ 2015-01-08 ]

@Massimo Siani:
I have done the same changes in my local code(1.1.7 release of mariadb java client library) and it works.

From your above comments, i see that the issue is fixed. But i am unable to find the code checked in so that i can use it in my project.
Can you give me the location from where i can get the latest java client jar/ repository location with the fix.

Generated at Thu Feb 08 03:13:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.