1

I have a java.lang.ExceptionInInitializerError when trying to execute BufferedImage originalImage = ImageIO.read(in);. This happens only on a production VM, not on my dev machine.

I created a small class with the above line on the production VM, compiled and executed it successfully. Then I tried adding java options "-Djava.awt.headless=true -Dawt.toolkit=sun.awt.HToolkit" as suggested here. Didn't help. Then I tried adding static {ImageIO.scanForPlugins();} as suggested here. Also didn't help. I ran jHades to try to see if there were any overlapping classes in jars. There are none.

Now I'm out of ideas. The dev machine is running java 1.8.0_76-release-b198 on Ubuntu 14.04 and the production VM runs java 1.8.0_60-b27 on CentOS. Any pointers?

Update: Full stack trace:

java.lang.ExceptionInInitializerError
    at com.comp.core.model.artifactThumbnails.ArtifactThumbnailRepository.generateThumbnail(ArtifactThumbnailRepository.java:63)
    at com.comp.core.model.artifactThumbnails.BigTableArtifactThumbnailRepository.createThumbnail(BigTableArtifactThumbnailRepository.java:71)
    at com.comp.web.routes.vertex.VertexThumbnail.handle(VertexThumbnail.java:90)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.web.privilegeFilters.PrivilegeFilter.handle(PrivilegeFilter.java:35)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.miniweb.handlers.CSRFHandler.handle(CSRFHandler.java:66)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.web.AuthenticationHandler.handle(AuthenticationHandler.java:17)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.miniweb.Router.dispatch(Router.java:93)
    at com.comp.miniweb.Router.routeWithExceptionHandling(Router.java:87)
    at com.comp.miniweb.Router.route(Router.java:44)
    at com.comp.miniweb.App.handle(App.java:128)
    at com.comp.web.WebApp.handle(WebApp.java:71)
    at com.comp.web.Router.service(Router.java:186)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at com.comp.web.RequestDebugFilter.doFilter(RequestDebugFilter.java:33)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:224)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
Caused by: 
java.lang.SecurityException: sealing violation: package com.sun.media.imageioimpl.plugins.jpeg is sealed
    at java.net.URLClassLoader.getAndVerifyPackage(URLClassLoader.java:399)
    at java.net.URLClassLoader.definePackageInternal(URLClassLoader.java:419)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at org.eclipse.jetty.webapp.WebAppClassLoader.findClass(WebAppClassLoader.java:510)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:441)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:210)
    at javax.imageio.spi.IIORegistry.<init>(IIORegistry.java:138)
    at javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:159)
    at javax.imageio.ImageIO.<clinit>(ImageIO.java:66)
    at com.comp.core.model.artifactThumbnails.ArtifactThumbnailRepository.generateThumbnail(ArtifactThumbnailRepository.java:63)
    at com.comp.core.model.artifactThumbnails.BigTableArtifactThumbnailRepository.createThumbnail(BigTableArtifactThumbnailRepository.java:71)
    at com.comp.web.routes.vertex.VertexThumbnail.handle(VertexThumbnail.java:90)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.web.privilegeFilters.PrivilegeFilter.handle(PrivilegeFilter.java:35)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.miniweb.handlers.CSRFHandler.handle(CSRFHandler.java:66)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.web.AuthenticationHandler.handle(AuthenticationHandler.java:17)
    at com.comp.miniweb.HandlerChain.next(HandlerChain.java:18)
    at com.comp.miniweb.Router.dispatch(Router.java:93)
    at com.comp.miniweb.Router.routeWithExceptionHandling(Router.java:87)
    at com.comp.miniweb.Router.route(Router.java:44)
    at com.comp.miniweb.App.handle(App.java:128)
    at com.comp.web.WebApp.handle(WebApp.java:71)
    at com.comp.web.Router.service(Router.java:186)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at com.comp.web.RequestDebugFilter.doFilter(RequestDebugFilter.java:33)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:224)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
Community
  • 1
  • 1
Johnny
  • 7,073
  • 9
  • 46
  • 72
  • are you using the standart Oracle's JVM or the Open JDK ? – AntJavaDev Jul 21 '16 at 08:04
  • Open JDK on dev, Oracle on production. – Johnny Jul 21 '16 at 08:09
  • `ImageIO` class is really dependent on the OS / JDK combination. Dont you have any other Cent OS to test it on it ? Also i dont know if it will help you , check the solution provided by Apache Commons [here](https://commons.apache.org/proper/commons-imaging/) and some examples [here](https://commons.apache.org/proper/commons-imaging/sampleusage.html) – AntJavaDev Jul 21 '16 at 08:15
  • I tested it on two identical production VMs running CentOS. I don't think it's an issue with the underlying JVM/OS because when I created a small class with the offending line I was able to run it. – Johnny Jul 21 '16 at 08:47
  • when you say you created the small class , you were able to replicate exactly the issue thats happening on the production environment ? i mean maybe in your scenario , the file you want to read is `null` – AntJavaDev Jul 21 '16 at 08:49
  • That's the thing. I successfully ran the small class on production. I'm guessing there's something interfering with ImageIO in the project but I don't know what. – Johnny Jul 21 '16 at 08:55
  • The image file I'm trying to read is definitely not null as I can see its size. – Johnny Jul 21 '16 at 09:03
  • so you cant replicate exactly the scenario ? because if something its interfering with the `ImageIO` i suppose you should have the same version of the project in your development system. So if you do exactly the same scenario in development system , it operates properly ? – AntJavaDev Jul 21 '16 at 09:35
  • ImageIO.read(in); does not throw ExceptionInInitializerError – gpasch Jul 21 '16 at 12:07
  • @AntJavaDev, yep, works perfectly. – Johnny Jul 21 '16 at 12:53
  • hmm as suggested by @gpasch , could you post your whole stacktrace ? to check exactly who is throwing the exception – AntJavaDev Jul 21 '16 at 14:11
  • Sure, I've added it. – Johnny Jul 21 '16 at 14:59
  • oh ok your stacktrace implies something else , check this [answer](http://stackoverflow.com/questions/10093176/java-lang-securityexception-sealing-violation) , you might have the same ImageIO jar in your classpath. or else a workaround from [here](http://bugs.java.com/view_bug.do?bug_id=6714839) says to change the manifest and remove the line sealed: true – AntJavaDev Jul 21 '16 at 16:36
  • The sealing violation (`package com.sun.media.imageioimpl.plugins.jpeg`) suggests that you have multiple instances of `jai_imageio.jar` in your application's class path. If you have one in your app's `WEB-INF/lib`, you can try to remove that one. Other places to look for it, might be the web container's (Jetty's) shared lib folder, or the JRE's `lib/ext` ("extensions") folder. – Harald K Jul 26 '16 at 18:55
  • That was exactly it, thanks! If you put it in an answer I'll mark it as accepted. – Johnny Aug 01 '16 at 11:35

0 Answers0