Bug #24598 Possible NPE in com.mysql.jdbc.Connection
Submitted: 26 Nov 2006 16:04 Modified: 19 Dec 2007 14:36
Reporter: Nils Hammar Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.0.4 OS:Any (Any)
Assigned to: CPU Architecture:Any

[26 Nov 2006 16:04] Nils Hammar
Description:
The variable histogramCounts on line 1587 in the file com.mysql.jdbc.Connection may be null and can cause a NullPointerException.

Code:

	if (histogramCounts == null) {
		createInitialHistogram(histogramBreakpoints,
				currentLowerBound, currentUpperBound);
	}

	for (int i = 0; i < HISTOGRAM_BUCKETS; i++) {
		if (histogramBreakpoints[i] >= value) {
			histogramCounts[i] += numberOfTimes;
			break;
		}
	}

How to repeat:
Compiler warning.

Suggested fix:
Proposed code:

	if (histogramCounts == null) {
		createInitialHistogram(histogramBreakpoints,
			currentLowerBound, currentUpperBound);
	} else {
		for (int i = 0; i < HISTOGRAM_BUCKETS; i++) {
			if (histogramBreakpoints[i] >= value) {
				histogramCounts[i] += numberOfTimes;
   
				break;
			}
		}
	}
[28 Nov 2006 12:19] Tonci Grgin
Hi Nils and thanks for your report.
I can't repeat it with latest sources in Eclipse and Ant 1.6.5.

Can you please try building from our source repo at 
http://svn.mysql.com/svnpublic/connector-j/branches/branch_5_0/connector-j?
[28 Nov 2006 12:20] Tonci Grgin
Build log

Attachment: BuildLog5-0-5.zip (application/x-zip-compressed, text), 1.02 KiB.

[28 Nov 2006 18:23] Nils Hammar
The warning is still present for me (using Eclipse 3.3M3) with "Null reference" warning enabled in the project properties. (Same also for bugs 24597 and 24599)

Method is addToHistogram() in Connection.java.
[19 Dec 2007 14:36] Mark Matthews
Fixed in 5.1 svn repo.