Skip to content

Commit

Permalink
Fix for Bug#25650305, GETDATE(),GETTIME() AND GETTIMESTAMP() CALL WITH
Browse files Browse the repository at this point in the history
NULL CALENDAR RETURNS NPE.
  • Loading branch information
soklakov committed Jun 13, 2017
1 parent 4e93573 commit 6b83353
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 5.1.43

- Fix for Bug#25650305, GETDATE(),GETTIME() AND GETTIMESTAMP() CALL WITH NULL CALENDAR RETURNS NPE.

- Fix for Bug#26239946, C/J 5.1 GIS TESTS ARE FAILING WITH MYSQL 8.0.1.

- Fix for Bug#26090721, CONNECTION FAILING WHEN SERVER STARTED WITH COLLATION UTF8MB4_DE_PB_0900_AI_CI.
Expand Down
4 changes: 2 additions & 2 deletions src/com/mysql/jdbc/ResultSetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5356,7 +5356,7 @@ public Time getTime(int columnIndex) throws java.sql.SQLException {
* if a database-access error occurs.
*/
public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException {
return getTimeInternal(columnIndex, cal, cal.getTimeZone(), true);
return getTimeInternal(columnIndex, cal, cal != null ? cal.getTimeZone() : this.getDefaultTimeZone(), true);
}

/**
Expand Down Expand Up @@ -5605,7 +5605,7 @@ public Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException {
* if a database-access error occurs.
*/
public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
return getTimestampInternal(columnIndex, cal, cal.getTimeZone(), true);
return getTimestampInternal(columnIndex, cal, cal != null ? cal.getTimeZone() : this.getDefaultTimeZone(), true);
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/testsuite/regression/ResultSetRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5383,4 +5383,48 @@ public Void call() throws Exception {
}
}
}

/**
* Tests for fix to BUG#25650305 - GETDATE(),GETTIME() AND GETTIMESTAMP() CALL WITH NULL CALENDAR RETURNS NPE
*
* @throws Exception
* if the test fails
*/
public void testBug25650305() throws Exception {
if (!versionMeetsMinimum(5, 6, 4)) {
return; // fractional seconds are not supported in previous versions
}

createTable("testBug25650305", "(c1 timestamp(5))");
this.stmt.executeUpdate("INSERT INTO testBug25650305 VALUES ('2031-01-15 03:14:07.339999')");

Calendar cal = Calendar.getInstance();

Connection testConn;
Properties props = new Properties();
props.setProperty("useSSL", "false");
props.setProperty("useFastDateParsing", "true");

for (int i = 0; i < 2; i++) {
System.out.println("With useFastDateParsing=" + props.getProperty("useFastDateParsing"));
testConn = getConnectionWithProps(props);
this.rs = testConn.createStatement().executeQuery("SELECT * FROM testBug25650305");
this.rs.next();

assertEquals("2031-01-15", this.rs.getDate(1).toString());
assertEquals("2031-01-15", this.rs.getDate(1, cal).toString());
assertEquals("2031-01-15", this.rs.getDate(1, null).toString());

assertEquals("03:14:07", this.rs.getTime(1).toString());
assertEquals("03:14:07", this.rs.getTime(1, cal).toString());
assertEquals("03:14:07", this.rs.getTime(1, null).toString());

assertEquals("2031-01-15 03:14:07.34", this.rs.getTimestamp(1).toString());
assertEquals("2031-01-15 03:14:07.34", this.rs.getTimestamp(1, cal).toString());
assertEquals("2031-01-15 03:14:07.34", this.rs.getTimestamp(1, null).toString());

testConn.close();
props.setProperty("useFastDateParsing", "false");
}
}
}

0 comments on commit 6b83353

Please sign in to comment.