Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalArgumentException criteriaFind

 
Mario Zott
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
do you think it is a good idea to throw IllegalArgumentExceptions if the criteria String specified for the criteriaFind method is null, contains a field not in db or is some kind of malformed...?
thank for your oppinions... mario
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just return all records. It's simpler to equate null to an empty string than to throw exceptions.
 
Junilu Lacar
Bartender
Pie
Posts: 8793
81
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you decide to do, it is important to spell this out in your JavaDoc comment. Also, the instructions specifically state how the criteriaFind method should behave when an invalid field name is specified in the criteria string.
 
Mario Zott
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for replies...
returning null in these cases seems the best way... and like it is cleary written in the specification:
"In the event of an invalid field name being provided as part of the criteria the behavior of this method is the same as if no records matched correctly specified criteria."
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mario Zott:
returning null in these cases seems the best way... and like it is cleary written in the specification: "In the event of an invalid field name being provided as part of the criteria the behavior of this method is the same as if no records matched correctly specified criteria."
In the event of an invalid field name, yes. To my mind, this is completely different from having a malformed criteria String. Arguably, a malformed criteria String would indicate a programming bug on the part of whoever uses your Data API. In the Java world, there is a standard way to handle any programming bugs that you detect, and that is to throw some flavour of RuntimeException. In this case, IllegalArgumentException is entirely appropriate.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic