• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

handling common loopholes

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sloppy programming and poorly design test plans are a bad combination.
 
Udayan Kumar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most MVC frameworks can take over this nasty work from you.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example: http://commons.apache.org/validator/
 
reply
    Bookmark Topic Watch Topic
  • New Topic