Native lib loading fails sometimes w/ gradle daemon


(Jan Berkel) #1

I’m integrating with 7-Zip-JBinding, the native lib loading is done in a static initializer in the task:

class SevenZipTask {
    static {
        SevenZip.initSevenZipFromPlatformJAR()
    }
    // ...
}

Without daemon mode everything works fine but otherwise I get the following error occasionally:

Caused by: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: 7-Zip-JBinding initialization failed: Error loading native library: '/var/folders/c6/z3r5wbx12xbg8cr02qwtsckh0000gn/T/SevenZipJBinding-3WETT8VykI4m/lib7-Zip-JBinding.dylib'
	at net.sf.sevenzipjbinding.SevenZip.loadNativeLibraries(SevenZip.java:651)
	at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJARIntern(SevenZip.java:455)
	at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(SevenZip.java:339)
	at net.sf.sevenzipjbinding.SevenZip$initSevenZipFromPlatformJAR.call(Unknown Source)
	at SevenZipTask.<clinit>(SevenZipTask.groovy:30)
	... 77 more
Caused by: java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/c6/z3r5wbx12xbg8cr02qwtsckh0000gn/T/SevenZipJBinding-3WETT8VykI4m/lib7-Zip-JBinding.dylib already loaded in another classloader
	at net.sf.sevenzipjbinding.SevenZip.loadNativeLibraries(SevenZip.java:649)
	... 81 more

Until the daemon is killed manually.

Catching the throwable is not an option since there are some other checks inside other library calls which might retrigger the library load. The different class loaders probably confuse the lib loading code.

A similar problem was already mentioned in the following thread, which did not get any replies: