aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes what to do about these exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "what to do about these exceptions" Watch "what to do about these exceptions" New topic
Author

what to do about these exceptions

Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
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,


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
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

Joined: Jan 30, 2002
Posts: 3451
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 ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
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

Joined: Jan 30, 2002
Posts: 3451
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

Joined: May 13, 2002
Posts: 301
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

Joined: Jul 11, 2002
Posts: 162
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?


swimming certificate (A & B), shoelaces diploma, and some useless java ones.
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
I had my constructor call the integrity check... but I have not gotton my results back from sun
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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

Joined: Dec 13, 2002
Posts: 96

[ December 30, 2002: Message edited by: Daniela Ch ]
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
what is the name of this design pattern?is it one?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what to do about these exceptions