{"id":326,"date":"2008-05-15T20:55:17","date_gmt":"2008-05-16T01:55:17","guid":{"rendered":"http:\/\/unitstep.net\/?p=326"},"modified":"2008-05-15T20:56:15","modified_gmt":"2008-05-16T01:56:15","slug":"the-importance-of-draconian-validation-for-method-parameters","status":"publish","type":"post","link":"https:\/\/unitstep.net\/blog\/2008\/05\/15\/the-importance-of-draconian-validation-for-method-parameters\/","title":{"rendered":"The importance of Draconian validation for method parameters"},"content":{"rendered":"
I recently ran into a problem where the callers of one of my methods was using it improperly by suppling a parameter that did not conform to the required values. However, the problems did not surface until I changed the implementation; previously, things worked by chance<\/em> due to an implementation detail.<\/p>\n I had been using input validation, but my validation procedure was not stringent enough to detect the improper parameter. This was tied to the fact that before the implementation change, things worked perfectly fine even with the improper inputs. However, the implementation change “broke” this work flow. All of this has led me to believe in the great importance of:<\/p>\n Let me go into some more detail.<\/p>\n <\/p>\n I had written a method that would accept a FQDN (Fully-Qualified Domain Name) as its argument. The purpose of this method was to retrieve some information over HTTPs from the web server running on the server with the specified domain. Since domain names are protocol-neutral (i.e. they aren’t preceded by something like “http:\/\/”), I ended up forming a \n
Unintended consequences<\/h3>\n
URL<\/acronym><\/code> object based on the FQDN, since eventually I’d be retrieving information over HTTPs anyways:<\/p>\n
final URL<\/acronym> url = new URL<\/acronym>(\"https:\/\/\" + fqdn + \"\/path_to_service\");<\/code><\/pre>\n