Bug #94533 | getObject for boxed primitive types doesn't return null for NULL columns | ||
---|---|---|---|
Submitted: | 3 Mar 2019 12:58 | Modified: | 11 Jan 2020 17:08 |
Reporter: | Michal Rehacek | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S3 (Non-critical) |
Version: | 8.0.15 | OS: | Any |
Assigned to: | Alexander Soklakov | CPU Architecture: | Any |
Tags: | getObject |
[3 Mar 2019 12:58]
Michal Rehacek
[6 Mar 2019 8:09]
Alexander Soklakov
Hi Michal, Thanks for the report. Verified as described.
[6 Mar 2019 12:18]
Alexander Soklakov
Michal, I'd say it's not a bug. JDBC API requires this for getLong(x): "if the value is SQL NULL, the value returned is 0". And I can't find any note in JDBC specification that getObject(x, Long.class) should have a different behaviour, in case of NULL value, than getLong(x).
[6 Mar 2019 13:13]
Michal Rehacek
Hello Alexander, let me explain why I think getObject( xxx, Long/Integer/etc.class ) should be returning null. It's a combination of two paragraphs in the JDBC standard that make me believe so: --- 15.2.3.3 - Retrieving NULL values Quote: ... Column values that map to Java Object types are returned as a Java null; those that map to numeric types are returned as 0 ... --- Table B-3 JDBC Types Mapped to java Object Types Quote: ResultSet.getObject and CallableStatement.getObject use the mapping shown in TABLE B-3 for standard mappings and the actual table shows that BIGINT maps to Long (with capital L, i.e. the Object long type) --- The first reference says that NULL column values mapped to Java Object should be returned as Java null. And the second table says that Long (capital L) is considered an object type. Similarly for the other object types that box the primitives.
[6 Mar 2019 14:35]
Alexander Soklakov
Hi, Michal! You're right. Also, while getObject(int columnIndex, Class<T> type) behaviour is not described in API, other getObject() methods documentation says "If the value is an SQL NULL, the driver returns a Java null". So, yes, we need to do the requested fix.