Skip to content

JDBC: Fix stackoverflow on getObject and timestamp conversion #31735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
throw new SQLException("type is null");
}

return getObject(columnIndex, type);
return convert(columnIndex, type);
}

private <T> T convert(int columnIndex, Class<T> type) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static Object convert(Object v, JDBCType columnType) throws SQLException {
case REAL:
return floatValue(v); // Float might be represented as string for infinity and NaN values
case TIMESTAMP:
return ((Number) v).longValue();
return new Timestamp(((Number) v).longValue());
default:
throw new SQLException("Unexpected column type [" + columnType.getName() + "]");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.joda.time.ReadableDateTime;

import java.sql.JDBCType;
import java.sql.Timestamp;

import static org.hamcrest.Matchers.instanceOf;

Expand Down Expand Up @@ -41,8 +42,8 @@ public void testDoubleAsNative() throws Exception {

public void testTimestampAsNative() throws Exception {
DateTime now = DateTime.now();
assertThat(convertAsNative(now, JDBCType.TIMESTAMP), instanceOf(Long.class));
assertEquals(now.getMillis(), convertAsNative(now, JDBCType.TIMESTAMP));
assertThat(convertAsNative(now, JDBCType.TIMESTAMP), instanceOf(Timestamp.class));
assertEquals(now.getMillis(), ((Timestamp) convertAsNative(now, JDBCType.TIMESTAMP)).getTime());
}

private Object convertAsNative(Object value, JDBCType type) throws Exception {
Expand Down