Bug #30851 NullPointerException in ResultSet.getString() when padCharsWithSpace set
Submitted: 6 Sep 2007 10:48 Modified: 11 Sep 2007 18:39
Reporter: Fred Dalle
Status: Closed
Category:Connector/J Severity:S2 (Serious)
Version:5.0.7 OS:Any
Assigned to: Target Version:
Tags: NullPointerException padCharsWithSpace

[6 Sep 2007 10:48] Fred Dalle
Description:
When fetching a null value from a CHAR column with padCharsWithSpace set, a NPE occurs at
com.mysql.jdbc.ResultSet.getString(ResultSet.java:5553)

the reason is of course that stringVal is null in

int currentLength = stringVal.length();
 

How to repeat:
create table with nullable CHARCOL, and insert a null value in it.
connect with padCharsWithSpace=true
fetch from the table with getString().

Suggested fix:
change the if around the block
from:

if (this.padCharsWithSpace) {

to:

if (this.padCharsWithSpace && (stringVal != null) ) {
[6 Sep 2007 12:38] Tonci Grgin
Hi Fred and thanks for excellent report.

Verified as described by checking the code with latest 5.0 branch sources:
Connected to 5.0.48-pb1038-log
java.vm.version         : 1.5.0_12-b04
java.vm.vendor          : Sun Microsystems Inc.
java.runtime.version    : 1.5.0_12-b04
os.name                 : Windows XP
[6 Sep 2007 12:43] Tonci Grgin
Test case

Attachment: TestBug30851.java (text/java), 1.46 KiB.

[6 Sep 2007 12:58] Fred Dalle
It's unclear to me what bug status 'verified' means...

Does it mean that 'someone' wrote and ran a repro, and it passes against the latest code
base
or
does it mean that 'someone' wrote and ran a repor, and that the bug report was verified
and indeed a bug?

Because in the repro, I don't see the actual connection being made, so I'm noit sure
whether the padCharsWithSpace=true connection option is set, that option is crucial to
reproduce the npe!
[6 Sep 2007 13:15] Tonci Grgin
Fred, "Verified" means that the problem is there and repeatable test case exists (or it's
obvious from looking in code or both, like in this case). Now we wait for dev lead to
assign someone to fix this problem.

You don't see my connection string as I use Eclipse and it's set on JVM level. I always
use latest sources for testing as it is in our SOP.

In short, "Verified" means you found actual repeatable bug and developer will be assigned
to fix it.

Thanks for your interest in MySQL!
[6 Sep 2007 16:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33822
[6 Sep 2007 16:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33824
[6 Sep 2007 16:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33826
[6 Sep 2007 17:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33832
[7 Sep 2007 16:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33909
[11 Sep 2007 18:39] MC Brown
A note has been added to the 5.0.8 and 5.1.3 changelogs: 

NPE with null column values when padCharsWithSpace is set to true.
[3 Oct 2007 18:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34839
[3 Oct 2007 18:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34840
[3 Oct 2007 20:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34855
[5 Oct 2007 20:53] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35011
[11 Oct 2007 22:11] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35407
[11 Oct 2007 22:24] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35410
[11 Oct 2007 22:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35414
[19 Nov 2007 1:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38019
[19 Nov 2007 3:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38024