Bug in Boolean.parseBoolean?
next code is supposed to print "1", "2","3" to stdout (at least intution says so) :
But it actually returns "1","2", since the Boolean API arbitrarily decides (with no further explanation) that a null maps to false, not raising any parsing exception. From my point of view this is a big error and breaks the "simetry" with the rest of the parse* functions.
It promotes buggy code. For example next code will produce random errors if other piece of software forgets to send the proper HTTP parameters.
boolean bFlagActive = Boolean.parseBoolean(request.getParameter("parameter1"));
boolean bFlagNoActive = Boolean.parseBoolean(request.getParameter("parameter2"));
Certainly, it's always possible to check for null values but people used to other similar APIs (parseInt, LarseLong,...) will expect an exception to be raised and most probably will not check for it. And what's even worse, since ParseException derives from java.lang.Exception java editors (Netbeans/Eclipse) will find it difficult to notify when the catch exception is needed and when it's not (providing a hint that something doesn't work as expected). Even unit-tests will randomly fail 50% of times!.
Guess it ought to be deprecated in favor of something more intuitive and less risky. For example:
parseBoolean(String booleanRepresentation, Boolean defaultValue);
so that it will return the defaultValue in case (booleanRepresentation==null && defaultValue!=null) or raise an new exception in case (booleanRepresentation==null && defaultValue==null).