aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes validation on null string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "validation on null string" Watch "validation on null string" New topic
Author

validation on null string

Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
This is referred to validation on the data access level: update and create. What should I do with a null string for a field? (surely it is best to be filtered at client and business logic, but sun's testing can directly call on this level.)

For example: I think of options for create (this is not required in client and thus in business logic):
1. disallow null field -- exception
2. replace \0 padding with spaces
3. simply don't verify.

The option 3 is error prone, since if the last field for create is null, it will result in an incomplete data format.

Any idea?


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Hi, Andy. I may be of help in your question. If you have a null string, it is best to convert it to "" and pad it with whitespace for update and create.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Thanks.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Andy,
checking for a null values depends on the business logic of specific method. Sometimes it is acceptable and sometimes it is not. For example: a primary key field in a record cannot be null, and an optional field might be ok to be null. If you don't allow null values in your methods, you must throw a checked exception and mention that in the method documentation. You can use IllegalArgumentException or NullPointerException. Personally, when I validate passing parameters, I use IllegalArgumnetException.


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Thanks, Hanna. You made some good points. But even the definition of primary key in this assignment is vague. But the illegal arg ex is a way to handle it.

Thanks.
 
Consider Paul's rocket mass heater.
 
subject: validation on null string
 
Similar Threads
Regular Expression
System.arraycopy() or clone().
Strategy to place validation
Who should verify the sanity of data?
NX: Validation in update, create methods