Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what to do about these exceptions

 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just about to turn in my assignment and I went to test it one more time and ran into these exceptions when trying to open my README.txt file and some other file... it works fine if the file does not exist.

Exception in thread "main" java.lang.OutOfMemoryError

Exception in thread "main" java.lang.NegativeArraySizeException
at suncertify.db.Data.<init>(Data.java:43)
at suncertify.db.LocalData.<init>(LocalData.java:21)
at suncertify.client.ConnectionFactory.<init>(ConnectionFactory.java:36)
at suncertify.client.ConnectionFactory.getConnection(ConnectionFactory.j
ava:73)
at suncertify.client.FBNController.<init>(FBNController.java:33)
at suncertify.client.FBNMain.main(FBNMain.java:85)

Thanks,
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is one solution... is this bad?
put a try-catch block in the Data contructor that catches Error and then rethrow an IO exception.
What do you think?
[ August 09, 2002: Message edited by: Nate Johnson ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nate,
I did the same thing and got the same error. Further investigation revealed that it happens when the Data constructor generates the schema (FieldInfo[]). I created a class called DBFileCheck which had one public static method called checkDB that ran a partial integrity check to verify that it was in fact a db file. If it wasn't, I threw an InvalidDataFileException which extended IOException.
Catching Error is probably an excercise in futility because there is no guarantee that you can do anything like send the exception up the chain.
Hope this helps,
Michael Morris
[ August 09, 2002: Message edited by: Michael Morris ]
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I stepped through my code and that is thee exact place it it dying... it is trying to create the array of about a zillion bytes.
I am not so good with databases, but if I were to do some sort of partial integrity check, would I just assume that I knew the headerLen should be equal to 128 and that nFields should be 9 since it is this kind (the sun db.db) of database and do the check that way? Or am I way off track?
Thanks
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nate,
That's it. Just verify that the header is correct and the Data constructor will do the rest. You should have a test at the end similar to:

Michael Morris
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Michael! I wrote an integrity check and now I can't get any files to do anything bad... only valid db.db files work (does not have to be named db.db though )
Thanks!
I think I am ready to submit now (after a bit more testing that is).
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the above is true and i found that as well.
My question is where do you guys handle this. Do you call this static function before creating the Data object or did you change the Data constructor. ?
Changing the data constructor is basically against the rules, but it is the right place to do it.
Calling the static function before creating the data object does not really make sense in an OO world. (my view)
so how did you solve this?
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had my constructor call the integrity check... but I have not gotton my results back from sun
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a singleton called DataFactory that mapped (and instatiated) Data objects to db files. That's where I called it, just before constructing the Data object. If IOException were thrown either by my integrity check or Data's, I then wrapped that Exception into an InvalidDataFileException which let the server (or client in local mode) know that the db file was corrupt or non-existant.
Michael Morris
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ December 30, 2002: Message edited by: Daniela Ch ]
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the name of this design pattern?is it one?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic