[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Files and Exceptions



On Wed, 08 Mar 2000, William Uther wrote:
> Hi all,
> 
>   I was just trying to debug Ozone on my machine and I noticed something
> disturbing: Ozone does not always close files after reading from them.  On
> systems with a limited number of open files (like most of them), this is
> bad.  (finalizers are not guaranteed to run in finite time.)
> 
>   Even when files are closed, they are usually not correctly enclosed in
> try {} finally {} blocks.  The correct way to do this is:
> 
> 	FileInputStream fin = null;
> 	try {
> 		fin = new FileInputStream("MyFile");
> 		// do stuff with fin
> 	} finally {
> 		if (fin != null)
> 			fin.close();
> 	}
> 
>   Here the file is always closed even if an exception is thrown.  This is
> covered in more detail here:
> <http://developer.java.sun.com/developer/TechTips/1998/tt0915.html> and
> <http://developer.java.sun.com/developer/TechTips/2000/tt0124.html#tip1>.
> This is especially important for a program like the Ozone server that
> catches all exceptions and keeps running rather than shutting down.

Good point. I will fix this.


Falko

> 
> This needs to be fixed in the following places that I found:
> 
>  core
>   wizardStore
>    ClusterStore.java
>     readCluser()
>     writeCluster()
>    WizardStore.java
>     startup()
>     shutdown()
>   Env.java
>    initSetup()
>    storeSetup()
>  tools
>   Statistics.java
>    readStats()
>    writeStats()
>   Install.java
>    resetStateFile()
>    resetConfigFile()
>  DxLib
>   DxDiskHashMap.java
>    re_use()
>    close()
>   DxDiskSubTable.java
>    readTable()
>    writeTable()
> 
> later,
> 
> \x/ill         :-}
-- 
______________________________________________________________________
Falko Braeutigam                         mailto:falko@softwarebuero.de
softwarebuero m&b (SMB)                    http://www.softwarebuero.de