Bug #38504 The "G" suffix has two meanings to the connection property parser
Submitted: 31 Jul 2008 20:14 Modified: 30 Sep 2013 13:53
Reporter: Shawn Green Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S4 (Feature request)
Version:5.1.6 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[31 Jul 2008 20:14] Shawn Green
Description:
Connector/J allows for various suffixes to variable in order to make defining larger numbers easier.  For example 1K is equivalent to 1024, 1M = 1048576

The problem is with "G". While "g" is properly parsed to mean "* 1073741824", "G" has two potential states: 1073741824 or 1048576

See the source code snippet below (reformatted to reduce wrapping)

mysql-connector-java-5.1.6/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
~~~~~~~~~~~~~~~~~~~~~
void initializeFrom(String extractedValue) throws SQLException {
valueAsString = extractedValue;
	
if (extractedValue != null) {
	if (extractedValue.endsWith("k") //$NON-NLS-1$
		|| extractedValue.endsWith("K") //$NON-NLS-1$
		|| extractedValue.endsWith("kb") //$NON-NLS-1$
		|| extractedValue.endsWith("Kb") //$NON-NLS-1$
		|| extractedValue.endsWith("kB")) { //$NON-NLS-1$
		multiplier = 1024;
		int indexOfK = StringUtils.indexOfIgnoreCase(
					extractedValue, "k"); //$NON-NLS-1$
		extractedValue = extractedValue.substring(0, indexOfK);
	} else if (extractedValue.endsWith("m") //$NON-NLS-1$
		|| extractedValue.endsWith("M") //$NON-NLS-1$
		|| extractedValue.endsWith("G") //$NON-NLS-1$
		|| extractedValue.endsWith("mb") //$NON-NLS-1$
		|| extractedValue.endsWith("Mb") //$NON-NLS-1$
		|| extractedValue.endsWith("mB")) { //$NON-NLS-1$
		multiplier = 1024 * 1024;
		int indexOfM = StringUtils.indexOfIgnoreCase(
				extractedValue, "m"); //$NON-NLS-1$
		extractedValue = extractedValue.substring(0, indexOfM);
	} else if (extractedValue.endsWith("g") //$NON-NLS-1$
		|| extractedValue.endsWith("G") //$NON-NLS-1$
		|| extractedValue.endsWith("gb") //$NON-NLS-1$
		|| extractedValue.endsWith("Gb") //$NON-NLS-1$
		|| extractedValue.endsWith("gB")) { //$NON-NLS-1$
		multiplier = 1024 * 1024 * 1024;
		int indexOfG = StringUtils.indexOfIgnoreCase(
					extractedValue, "g"); //$NON-NLS-1$
		extractedValue = extractedValue.substring(0, indexOfG);
	}
}

How to repeat:
Read the source code

- or - 

Assign a connection property a value with the M and another with the G suffixes then compare the parsed values.

Suggested fix:
Remove the "G" parsing line from the block of M-based tests.
[4 Sep 2008 13:09] Tonci Grgin
Verified by looking into sources.
[30 Sep 2013 13:53] Filipe Silva
This bug is duplicate of Bug#69452, please look there for further progress.