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

Null in the record field

 
Sergey Bylokhov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

Wrote a lot of tests for may program and was bitten by this problem
Now i understand that I do not understand this

All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field


What does it mean "null terminated if less than the maximum length for the field"??

For example i create a test which always fail in me Data class implementation

In error line i get an exception because I change all null fields to the empty String ("") befor save to the file And after save and reread field data changed
Probably its a bug? Its normal use case for creating or updating filed with null ?? Can i just throw an IAE in this situation?

Thanks for help



 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sergey,

Of course it all depends on how you implemented your update-method. In my update-method a null-value in the newData array is ignored; if you want to empty a String you have to pass an empty String. But that's of course how I implemented my update-method. You are completely free to implement some other logic.

What does it mean "null terminated if less than the maximum length for the field"??
I didn't care about that line, because the original database file just contains spaces until the end (of that field). So for a field name with length of 8, Roel is saved as "Roel____" (underscore = space). And my read-method just trims any value read from the database file (so "Roel____" becomes "Roel").

My create-method does not allow null-values, so if you'll try to invoke that method with 1 null-value in the array you'll get an IAE. In my update-method null-values are allowed (and as said: these values are just ignored). Everything is documented in javadoc comments (what is expected, which exceptions might be thrown,...).

It is all up to you to create a solid API (Data class). So using null-values in update-method is not a problem (unless you define it yourself). But if you state that null-value will be saved as an empty String, you can do to things to resolve the error:
  • change your assert to assertArrayEquals(instance.read(1), new String[] {"", "", "", "", "", ""});
  • change your read-method to change an empty String to null

  • Kind regards,
    Roel
     
    Daniel Breitner
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    One more question to that topic ...

    my assignment reads

    but because the data must continue to be manipulated for reports using another custom-written application, the new system must reimplement the database code from scratch without altering the data file format.



    Does that mean that the other application will use MY data implementation or that the other application will directly write into the data file ? Because if it does I would still have to deal with that null terminated stuff ...
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Daniel,

    Does that mean that the other application will use MY data implementation or that the other application will directly write into the data file ?
    The other application will use the data file too and write directly into it.

    Because if it does I would still have to deal with that null terminated stuff ...
    No, it doesn't. Because the data file you got was already padded with spaces and it is also used by another application (according to instructions) and you are not sure if that other application could handle null terminated values. (that's an altered snippet from my choices.txt by the way)

    Kind regards,
    Roel
     
    Daniel Breitner
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No, it doesn't. Because the data file you got was already padded with spaces and it is also used by another application (according to instructions) and you are not sure if that other application could handle null terminated values. (that's an altered snippet from my choices.txt by the way)


    What I meant was : What if the other application writes null values into the data file ? Then I would have to deal with, it, right ?


     
    Daniel Breitner
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    oh wait ... I think trim() also removes the null termination, right ?
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Daniel Breitner wrote:What if the other application writes null values into the data file ? Then I would have to deal with, it, right ?
    In the file you get with your assignment (which is already used by the other application) only spaces are used to pad the values. I didn't handle null terminated values in my assignment, just used the trim() method when reading values from data file

    Kind regards,
    Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic