• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nulls in records not handled

 
Colin O'Toole
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Oh dear.

I submitted my project last week and was literally walking down the road today when it hit me that I'd completely forgotten to put in any checks in the create method for null record fields.

I am checking to ensure that the string array itself is not null and the string array is the right length for the schema. However, having a null field just slipped my mind and in all my unit testing I don't have one which tests this condition.

Sure enough I tested if when I got home and my file writing code throws a NPE in this situation. A stupid omission I know but is this enough to fail me automatically?

The moral of the story: when you're really really sure you're finished and it works perfectly, wait another week (or two) and THEN submit.

Colin.
 
Anton Golovin
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Colin O'Toole:
Hi all,

Oh dear.

I submitted my project last week and was literally walking down the road today when it hit me that I'd completely forgotten to put in any checks in the create method for null record fields.

I am checking to ensure that the string array itself is not null and the string array is the right length for the schema. However, having a null field just slipped my mind and in all my unit testing I don't have one which tests this condition.

Sure enough I tested if when I got home and my file writing code throws a NPE in this situation. A stupid omission I know but is this enough to fail me automatically?

The moral of the story: when you're really really sure you're finished and it works perfectly, wait another week (or two) and THEN submit.

Colin.



How would there be a null in record to begin with?
 
Colin O'Toole
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, from the GUI it's impossible, but perhaps Sun are using an automated test harness to call Data methods that the GUI doesn't use (create and delete). If they're adding records via the Data create method, they may test how the server will handle invalid records. Certainly I would, but then I'm paranoid.

But alas, not paranoid enough it seems . Hopefully the automated testing process isn't that complete.

Ah well, no use crying over spilt milk.
 
Anton Golovin
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Colin O'Toole:
Sure, from the GUI it's impossible, but perhaps Sun are using an automated test harness to call Data methods that the GUI doesn't use (create and delete). If they're adding records via the Data create method, they may test how the server will handle invalid records. Certainly I would, but then I'm paranoid.

But alas, not paranoid enough it seems . Hopefully the automated testing process isn't that complete.

Ah well, no use crying over spilt milk.


Don't worry about it. If they do test it, and it fails, then you will lose 2 marks, and that will be the end of it. Your Data class does operate according to the specifications overall, and this is a minor detail.
 
Colin O'Toole
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers Anton, I'm sure you're right - it was just a real d'oh! moment.

Thanks for the support, I'll have a beer and forget about it
 
Anton Golovin
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Colin O'Toole:
Cheers Anton, I'm sure you're right - it was just a real d'oh! moment.

Thanks for the support, I'll have a beer and forget about it


It's just not going to cause you to fail the exam.
 
Mogens Nidding
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry. Quoting Joshua Bloch's "Effective Java":
Item 40: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors.
.

Passing a null value is a violation of the precondition (whether you specified it or not), and thus a programming error, and there is nothing good the caller can do to recover anyway.

Usually, a NullPointerException will get thrown very soon after the null enters your method, so in most cases, it should be clear from the stack trace what went wrong. While it might have been very slightly better to check the arguments and throw an IllegalArgumentException as soon as possible (since we are talking about public methods), that's in my opinion just nitpicking, and should cost 2 points at most.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic