kucci / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

NullPointerException thrown during auto-unboxing of Boolean, Integer etc… #466

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare class variable Boolean myBool;
2. In any method add
if(myBool) {
   // block 1
} else {
   // this block is usually expected to run
}

What is the expected output? What do you see instead?
Unexperienced developer does not expect and usually do not understand why the 
NullPointerException thrown in condition of if

I resolved it by static methods:
public static boolean unbox(final Boolean obj)
public static boolean unbox(final Boolean obj, final boolean defaultValue)
etc. for all Numbers and Character

The methods can be also added to ObjectUtils

Original issue reported on code.google.com by valerav@gmail.com on 4 Nov 2010 at 11:04

Attachments:

GoogleCodeExporter commented 9 years ago
IMHO, it is better to teach your unexperienced developer how to program in 
Java. These methods will only add complexity.

Original comment by amer...@gmail.com on 4 Nov 2010 at 1:51

GoogleCodeExporter commented 9 years ago
Agreed.

Original comment by kevinb@google.com on 5 Nov 2010 at 12:11

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09