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.