[FIXED] Files cache was corrupted and applet never started again

Started by arielsan, March 07, 2011, 15:28:49

Previous topic - Next topic

arielsan

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:

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.

kappa

ah nice find (once again), will try patch later on today.

kappa

ok the patch is applied.

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