E. None of the above
The validation code checks that each character is between 0 and 9.
Since it is comparing to allowed values, this is an example of a whitelist, and option D is correct.
If it were the opposite, it would be a blacklist.
There is no such thing as a gray or orange list.
Hi, Shouldn't the answer be a blacklist?
The 816 book states,
A blacklist is a list of things that aren't allowed
The code example was looking for illegal chars and then throw an exception. If it was a whitelist, then it would also look for legal chars and then do something, not throwing an exception.
The whitelist example in the OCP 816 Kindle, page 885, checks for legal input and then do something. It does not throw an exception.
I wish I didn't write this question. It doesn't test whether you know the definition well.
The definition of a blacklist is a list of what isn't allowed.If something appears that is on the blacklist, the code should fail. A common example is "we don't allow $ or # in a string." It is an exhaustive list of characters that shouldn't appear.
The definition of a whitelist is a list of what is allowed. If something appears that isn't on the whitelist, the code should fail. So far, so good. A common example, is "we only allow letters". It is an exhaustive list of characters that are allowed to appear.
The problem here is that the answer depends on how you think about it. To me, this code says only letters are allowed, which is a whitelist.