LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: arielsan on March 07, 2011, 15:28:49

Title: [FIXED] Files cache was corrupted and applet never started again
Post by: arielsan on March 07, 2011, 15:28:49
Dunno how exactly happened but I was refreshing some page, testing something about the html content and suddenly the applet inside stopped to run, when I take a look at the Java console, it failed to read the cache, an exception related with the ObjectInputStream serialization. I tried to refresh the page and it always failed when reading the cache file. I removed the cache file from lwjgl cache and it worked.

To test the bug, open the lwjglcache, the application you want, and introduce some noise to the cache file, then try to run the application again.

In other words, it could happen that the cache file be corrupted then the applet will never work again, I propose to catch the exception when reading the cache and consider it as it doesn't exist:

Code: [Select]
protected HashMap<String, Long> readCacheFile(File file) throws Exception {
FileInputStream fis = new FileInputStream(file);
try {
ObjectInputStream dis = new ObjectInputStream(fis);
HashMap<String, Long> hashMap = (HashMap<String, Long>) dis.readObject();
dis.close();
return hashMap;
} catch (Exception e) {
// failed dunno why, could be StreamCorruptedException, IOException, etc
} finally {
fis.close();
}
// in case it fails, return an empty map
return new HashMap<String, Long>();
}

note: I have no tested that code, it is only a suggestion.
Title: Re: [BUG] Files cache was corrupted and applet never started again
Post by: kappa on March 07, 2011, 19:23:50
ah nice find (once again), will try patch later on today.
Title: Re: [BUG] Files cache was corrupted and applet never started again
Post by: kappa on March 07, 2011, 22:39:47
ok the patch is applied.

Thanks again for the recent stream of patches, tis brilliant stuff.