Upgrading to JDK 1.7 update 45, from 21, running in JBoss AS 7.2.0.Final (or EAP 6.1.0.Alpha1 (AS 7.2.0.Alpha1-redhat-4)) I am getting a NullPointerException
when initialising ImageIO
. Which is being used for image resizing during uploads.
IIORegistry
is called as part of the ImageIO
initialisation but it NPEs at this code:
public static IIORegistry getDefaultInstance() {
AppContext context = AppContext.getAppContext(); // <- context==null here??
However it doesn't have a problem when running outside JBoss (as a JUnit test for example).
I'm not sure when this behaviour changed but it was somewhere between JDK update 21 and 45 (from hints online it was probably update 25).
There are many similar (but not identical) tales of woe out there but none of the suggested solutions works here. They also relate to other servers than JBoss (WebSphere for example). So this appears to be a more generic container configuration problem.
I am running with both these (and the variations of using them or not):
-Djava.awt.headless=true
-Dawt.toolkit=sun.awt.HToolkit
JBoss imports the javax.imageio.*
packages by default. For evidence of that, see this which mentions javax.api, which refers to this module:
modules/system/layers/base/javax/api/main/module.xml
I've also tried adding them to jboss-deployment-structure.xml
explicitly:
<system>
<paths>
<path name="javax/imageio"/>
<path name="javax/imageio/event"/>
<path name="javax/imageio/metadata"/>
<path name="javax/imageio/plugins/bmp"/>
<path name="javax/imageio/plugins/jpeg"/>
<path name="javax/imageio/spi"/>
<path name="javax/imageio/stream"/>
</paths>
</system>
Note (for anyone else searching for this) also that when you first trigger this error you see this:
java.lang.NullPointerException
javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:155)
But on subsequent tries, without a server restart, you see this:
java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
Which is misleading - the class is available to the classloader but has been unloaded due to the first failure. So remember to restart the server before testing again.
It seems that something is preventing AppContext.getAppContext()
returning anything useful but currently I am at a loss as to what magic bit of config that is!