This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes handling common loopholes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "handling common loopholes " Watch "handling common loopholes " New topic
Author

handling common loopholes

Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi ,

This is more of a generic question about usage of sound programming practices. I am in the post-deployment phase of the application and now into defect management. Most of time in this phase I am investing in patching code with null checks, empty string checks, trimming spaces, caseSensitive handling etc.
Don't know if this is an indication of bad design or bad programming practices but typically this tends to be the case in most java projects and we end up doing a lot of paranoid programming with the aforementioned scattered through out the application.

I would like to know your feedback on this and is there a possibility of modularising all this nonBusiness (forgive me if this a heavy term) type of coding at central place(say entry point of the app) or externalizing etc so I can adopt a more optimistic programming style within the application least bothered to carry out null checks or empty strings or space/case sensitive issues.

Uday
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Frankly, I don't understand why you are doing this after deployment - is the code working, or is it not???

And can you give some simple code examples for what you are doing?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
Hi this should have been dealt during the development process, and this is where you would feel the power of StringUtils from apache, and other classes but mainly this class has a group of utility methods that could save a lot of time, to deal with all that null values, trimming ... etc.

StringUtils


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sloppy programming and poorly design test plans are a bad combination.
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
I guess I did not frame the post correctly.

Your viewpoints about testing/sloppy programming is well taken. My question was more about a solution regarding handling all of this in a centralised way and not bother to have such checks scattered across.

I don't know if this is a common practice but always having checks (if str!= null && !str.trim().equalsIgnoreCase("")) etc IMO is a lot of procedural clunkiness. May be my questions may sound basic and dumb but I am sure some experts here may have techniques about handling all this in an efficient manner only once within an application scope.
To rephrase a bit I am look at an xml world kind of checks where in bad input is ruled out at the entry level with schema validation failure. Is there a similar alternative in java space where in within the app scope i can code optimistically w/out worrying about bad input at all.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Udayan Kumar wrote:
I don't know if this is a common practice but always having checks (if str!= null && !str.trim().equalsIgnoreCase("")) etc IMO is a lot of procedural clunkiness. May be my questions may sound basic and dumb but I am sure some experts here may have techniques about handling all this in an efficient manner only once within an application scope.


Where is the string you are checking coming from?

(As an aside, the "ignoreCase" is absolutely superfluous for an empty string.)
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
The input is a custom java object from an external application.

Sorry about the superflous example. My bad. I was trying to make a generic statement typing hastily
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Most MVC frameworks can take over this nasty work from you.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Ah, so this really is about validation of input from an external program that isn't under your control. Get it.

There are a couple of frameworks out there for object validation. Googling for "java object validation" should give you some good hits. See whether they help you to get ideas.
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Thanks Ilja. Yes I was looking for something similar. Never had an idea about java object validation f/works.

If anyone has used similar frameworks let me know which are the more robust and popular ones.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Example: http://commons.apache.org/validator/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: handling common loopholes
 
Similar Threads
null in JSTL
Good book on methodologies
Ruby on Rails or the joy of instant feedback.
Exam Objectives Flow Control.
Idiom => Item 27 from Bloch's book