ClassGraph v4.8.52 Release Notes

Release Date: 2019-10-20 // over 4 years ago
  • ✂ Remove the shutdown hook entirely (#376).

    📚 A shutdown hook has been in place for numerous releases, and its purpose was to call ScanResult#close() on any open ScanResult instances before JVM shutdown, in order to free up resources (delete any temporary files that had to be created to extract deflated nested jars; unmap mapped byte buffers; close open modules; close open files; free up allocated memory; etc.). However the JVM's own shutdown processes should take care of all of these steps, including the removal of any temporary files that are created, as they are marked for deletion on JVM shutdown. More importantly, ScanResult implements Autocloseable, and the ClassGraph documentation strongly recommends assigning ScanResult in a try-with-resources block so that each ScanResult is properly closed, so the shutdown hook was always just a fallback.

    If you want to close all open (unclosed) ScanResult instances at once, you can call the new static method ScanResult.closeAll(). You might want to do this on container unload/destroy, in a containerized runtime.

    ClassGraph automatically registers lifecycle listeners for servlet containers and Spring applications that call ScanResult.closeAll(), to ensure that resources are properly freed when containers are destroyed or unloaded.

    Note that if you call ScanResult.closeAll(), you need to ensure that the lifecycle of the classloader matches the lifecycle of your application, or that two concurrent applications don't share the same classloader, otherwise one application might close another application's ScanResult instances while they are still in use.