[CONJ-405] Calendar instance not cleared before being used in ResultSet.getTimestamp Created: 2016-12-30  Updated: 2017-01-16  Resolved: 2017-01-12

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.4.6, 1.5.6
Fix Version/s: 1.5.7

Type: Bug Priority: Major
Reporter: Sebastian Lövdahl Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 16.04, MariaDB server 10.0.28


Attachments: Java Source File CalendarNotWorking.java     Java Source File CalendarWorking.java    

 Description   

I do understand that the reason behind problem I'm describing is an edge case and actually not even officially supported according to https://mariadb.com/kb/en/mariadb/date/ and https://mariadb.com/kb/en/mariadb/datetime/. However, I think it's possible that it could cause issues in other cases as well.

The Calendar instance used in MariaSelectResultSet.getTimestamp(byte[], ColumnInformation, Calendar) is not cleared before values are set in the synchronized block on lines 1656 to 1665.

This doesn't normally cause any problems, but if the year part of the datetime value is 0000 and useLegacyDatetimeCode=false is used the Calendar instance is corrupted and won't produce correct timestamps afterwards.

As can be seen below, the first number 3 in the CalendarNotWorking output is clearly incorrect.

Output from the two attached samples:

CalendarWorking:

With useLegacyDatetimeCode=true:
1, 2015-05-13 08:15:14: 1431494114000
2, 0000-11-15 10:15:22: -62139800678000
3, 2015-05-13 08:15:14: 1431494114000

CalendarNotWorking:

With useLegacyDatetimeCode=false:
1, 2015-05-13 08:15:14: 1431504914000
2, 0000-11-15 10:15:22: -62139793478000
3, 2015-05-13 08:15:14: -125712920686000
Clearing calendar..
3, 2015-05-13 08:15:14: 1431504914000



 Comments   
Comment by Sebastian Lövdahl [ 2017-01-16 ]

Thank you for resolving the issue quickly!

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