java - IllegalStateException: zip file closed during file write -
this bug occurs when program enters shutdown hook , tries write settings file text document. strange thing is, doesnt throw exception everytime.
exception in thread "thread-4" java.lang.illegalstateexception: zip file closed @ java.util.zip.zipfile.ensureopen(unknown source) @ java.util.zip.zipfile.getentry(unknown source) @ java.util.jar.jarfile.getentry(unknown source) @ java.util.jar.jarfile.getjarentry(unknown source) @ com.crimson.server.jarclassloader.findjarentry(jarclassloader.java:514) @ com.crimson.server.jarclassloader.findjarclass(jarclassloader.java:584) @ com.crimson.server.jarclassloader.loadclass(jarclassloader.java:956) @ java.lang.classloader.loadclass(unknown source) @ com.crimson.universalutils.datastore.store(datastore.java:66) @ com.crimson.server.servershutdownhook.run(servershutdownhook.java:38)
here datastore.store(settings):
public static file set = new file("settings.properties"); public static void store(settings settings){ set.delete(); try { set.createnewfile(); printwriter pw = new printwriter(set);//line 66 pw.println(objecttransfer.tostring(settings)); pw.close(); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
i dont know why creating printwriter calls classloader.loadclass, problem because im using jarclassloader: http://www.jdotsoft.com/jarclassloader.php
i checked source code of jarclassloader
, problem jarclassloader has shutdown hook close jar file. , documentation of shutdown hooks says, may invoked in order, or in parallel. when hook "gets in" before jarclassloader
s, code works. when it's bit late, exception.
a way around ensure printwriter
class loaded before invoking shutdown hook.
Comments
Post a Comment