File locked after JAXB error

I have a marshall / unmarshall JAXB process that works fine except for this: sometimes the files I have to use for unmarshall are empty or unformatted, so unmarshall throws an exception. This is normal, but after this exception, I'm unmarshalling (the original xml file of the Java object) is blocked. I can not use it.

I noticed this while trying to delete or rename the file right after the unmarshall exception. If an exception does not occur, the files can be used without problems, as it should be.

Is there a way to "unlock" these files? I think there must be some way to free, close, or free up JAXB context resources or the unmarshaller object that locked my file.

Thanks in advance,

Dani

+4
source share
1 answer

You can create a FileInputStream from your file and then undo it. Then you have more control over what happens when an error occurs.

 FileInputStream inputStram = new FileInputStream(file); Foo foo = (Foo) Unmarshaller unmarshal(inputStream); 
0
source

Source: https://habr.com/ru/post/1433892/


All Articles