• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation on null string

 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic