I ran into a NullPointerException in Configurations.java while attempting to compress an image within a Netty worker thread, which has a null context class loader.
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.ClassLoader.getResourceAsStream(String)" because the return value of "java.lang.Thread.getContextClassLoader()" is null
at net.coobird.thumbnailator.util.Configurations.init(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
at net.coobird.thumbnailator.util.Configurations.<clinit>(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.<init>(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
at net.coobird.thumbnailator.Thumbnails$Builder$InputStreamImageSourceIterator$1.next(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
at net.coobird.thumbnailator.Thumbnails$Builder$InputStreamImageSourceIterator$1.next(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source) ~[thumbnailator-0.4.20.jar:0.4.20]
...
Which traces back to this statement in Configurations.init():
InputStream resourceIs = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("thumbnailator.properties");
I'm working around it in my own environment by temporarily setting the context class loader to getClass().getClassLoader() before running Thumbnails.Builder.toFile().
I ran into a
NullPointerExceptioninConfigurations.javawhile attempting to compress an image within a Netty worker thread, which has anullcontext class loader.Which traces back to this statement in
Configurations.init():I'm working around it in my own environment by temporarily setting the context class loader to
getClass().getClassLoader()before runningThumbnails.Builder.toFile().