Bug #89672 MySQL BIT(>1) data type converted to java Boolean instead of byte[] type
Submitted: 14 Feb 2018 16:33 Modified: 15 Mar 2018 13:03
Reporter: Daniel Navrotsky Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.45 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[14 Feb 2018 16:33] Daniel Navrotsky
Description:
When fetching BIT(>1) column type from DB it is returned as Boolean type but should be byte[]. 

How to repeat:
Fetch column of type BIT(16) from DB and check returned type. Should be byte[2] but actual Boolean.

Suggested fix:
In version 5.1.39 the constructor of com.mysql.jdbc.Field class was checking the size of the BIT field and in case it was bigger than 1 the type was changed to Types.VARBINARY

if (this.mysqlType == MysqlDefs.FIELD_TYPE_BIT) {
	this.isSingleBit = (this.length == 0);

	if (this.connection != null && (this.connection.versionMeetsMinimum(5, 0, 21) || this.connection.versionMeetsMinimum(5, 1, 10))
			&& this.length == 1) {
		this.isSingleBit = true;
	}

	if (this.isSingleBit) {
		this.sqlType = Types.BIT;
	} else {
		this.sqlType = Types.VARBINARY;
		this.colFlag |= 128; // we need to pretend this is a full
		this.colFlag |= 16; // binary blob
		isBinary = true;
	}
}

But in version 5.1.40 this code was changed to this

if (this.mysqlType == MysqlDefs.FIELD_TYPE_BIT) {
	this.isSingleBit = this.length == 0
			|| this.length == 1 && (this.connection.versionMeetsMinimum(5, 0, 21) || this.connection.versionMeetsMinimum(5, 1, 10));

	if (!this.isSingleBit) {
		this.colFlag |= 128; // Pretend this is a full binary(128) and blob(16) so that this field is de-serializable.
		this.colFlag |= 16;
		isBinary = true;
	}
}

and there is no more conversion to type Types.VARBINARY
[15 Feb 2018 12:33] Chiranjeevi Battula
Hello Daniel Navrotsky,

Thank you for the bug report.
Could you please provide repeatable test case (exact steps, full stack trace, sample code etc. - please make it as private if you prefer) to confirm this issue at our end?

Thanks,
Chiranjeevi.
[15 Feb 2018 12:50] Daniel Navrotsky
Unfortunately, I don't have time for this. I can provide any additional info to let you build the test case if something not clear in the bug description. I pointed out the exact code lines where I suppose the bug was introduced and can be fixed. Also, it's a general issue and not limited to the particular use case.
[16 Mar 2018 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".