dcsimg
Is this a example of the paranoid style programming recommended by Terrence Parr?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, January 8, 2004 03:56 AM

			
private long getRequestedOpKey(HttpServletRequest request) {
long opKey = PageStateMachine.DEFAULT_OPKEY;
String opKeyStr = request.getParameter("opkey");
if ( opKeyStr!=null ) {
if ( opKeyStr!=null ) {
opKey = Long.parseLong(opKeyStr);
}
}
return opKey;
}


regards,

Manfred

Re: Is this a example of the paranoid style programming recommended by Terrence Parr?

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, January 8, 2004 09:53 AM

I don't know Terrence Parr or his recommendations, but if it were me I would probably write something like



String opKeyStr = request.getParameter("opkey");
if ((null == opKeyStr) || ("".equals(opKeyStr.trim))) {
// do some error handling, return INVALID_LONG
}
long opKey = INVALID_LONG;
try {
opKey = Long.parseLong(opKeyStr);
} catch (NumberFormatException e) {
// do some error handling, return INVALID_LONG
}

return opKey;

About | Sitemap | Contact