Error Instantiating Object - NoClassDefFoundError when accessing class in other jar file

I am trying to use the ortussolutions/commandbox:adobe2018 image for a container to run a Coldfusion application that is already working in a Windows instance and an instance based on the adobecoldfusion/coldfusion2018:2018.0.16 image.

When I try to launch the application on the CommandBox container, I get an error:

"Error","XNIO-1 task-1","05/17/23","13:12:22","AgencyManager","Object instantiation exception.An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor  explicitly using the init(args) method. Error : '' The specific sequence of files included or processed is: /app/index.cfm, line: 79 "
coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception.
	at coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:222)
	at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:96)
	...
	at cfMedispan2ecfc1665728274$funcLOADCLASSIFICATIONCACHE.runFunction(/app/packages/Medispan/Medispan.cfc:79)
	...
	at cfMedispan2ecfc1665728274$funcINIT.runFunction(/app/packages/Medispan/Medispan.cfc:16)
	...
	at cfsessionrefresh2ecfc969640930$funcLOADAPPLICATIONCACHE.runFunction(/app/AM/cfc/sessionrefresh.cfc:67)
	...
	at cfApplication2ecfc1572209739$funcONAPPLICATIONSTART.runFunction(/app/Application.cfc:343)
	...
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	...
	at runwar.undertow.SSLClientCertHeaderHandler.handleRequest(SSLClientCertHeaderHandler.java:144)
	at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	...
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1449)
	at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:216)
	... 111 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class medispan.logging.LogWriter
	at medispan.dib.Navigation.<init>(Unknown Source)
	... 116 more

The important part, I think, is the last couple of lines about not finding medispan.logging.LogWriter at medispan.dib.Navigation. The medispan.dib.Navigation class is in /usr/local/cflibs/Medispan/dib-4.0.0.jar, and the medispan.logging.LogWriter class is in /usr/local/cflibs/Medispan/mmwfoundation-3.2.0.jar.

I have my server.json file set up with libDirs to find the jar files:

...
  "app": {
    "libDirs": "/usr/local/lib/serverHome/,/usr/local/cflibs,/usr/local/cflibs/Medispan/*"
  },
...

and I can see both jar files get picked up when the server is starting -

It is weird that this does not work in the CommandBox container but will work on Windows and the adobe provided container. Does anyone have any ideas why it would act this way?

For reference, here is the whole server.json file I am using -

{
  "cfconfig": {
    "file": "test_cfconfig.json"
  },
  "profile": "development",
  "app": {
    "libDirs": "/usr/local/cflibs,/usr/local/cflibs/Medispan/*"
  },
  "example_fullsample": "https://commandbox.ortusbooks.com/embedded-server/server.json",
  "scripts": {
    "onServerInstall": "!sed -i \"s/{{MED_DB_USERNAME}}/$MED_DB_USERNAME/\" /usr/local/cflibs/Medispan/medispan.wkconfig.xml && sed -i \"s/{{MED_DB_PASS}}/$MED_DB_PASS/\" /usr/local/cflibs/Medispan/medispan.wkconfig.xml"
  },
  "jvm": {
    "minHeapSize": "${MIN_MEMORY}",
    "maxHeapSize": "${MAX_MEMORY}",
    "args": [
      "-Xms${MIN_MEMORY}",
      "-Xmx${MAX_MEMORY}",
      "-XX:MaxMetaspaceSize=${MaxMetaspaceSize}",
      "--add-opens=java.base/java.lang=ALL-UNNAMED",
      "--add-opens=java.base/java.nio=ALL-UNNAMED",
      "--add-opens=java.base/sun.util.cldr=ALL-UNNAMED",
      "--add-opens=java.base/sun.util.locale.provider=ALL-UNNAMED",
      "--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED",
      "-DDEBUGGER_SERVER_PORT=7777",
      "-Dcoldfusion.home={application.home}",
      "-Dcoldfusion.jsafe.defaultalgo=FIPS186Random",
      "-Dcoldfusion.libPath={application.home}/lib",
      "-Dcoldfusion.rootDir={application.home}",
      "-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true ",
      "-Dhttps.protocols=TLSv1.2",
      "-Djava.security.egd=/dev/urandom",
      "-Djava.util.logging.config.file={application.home}/lib/logging.properties",
      "-Djdk.attach.allowAttachSelf=true",
      "-Dorg.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER=true",
      "-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog",
      "-Dsun.font.layoutengine=icu",
      "-Duser.language=${language:en}",
      "-XX:+UseParallelGC",
      "-Xdebug",
      "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005",
      "-javaagent:/usr/local/newrelic/newrelic.jar",
      "-server"
    ]
  }
}

Restart the server, hit the code ONCE and report the full stack trace. Sometimes when there is an exception thrown during a java class’s constructor, the “real” will only be thrown the first time, and then all subsequent calls will be a generic error message. Its like Java only tries once and then stops trying. This only applies when the classes constructor errors.

How are you providing those two directories? Via mount or copying them in with a Dockerfile?

They get copied in with the Dockerfile, which looks like this:

FROM ortussolutions/commandbox:adobe2018

# ...

RUN box install commandbox-cfconfig

ENV TZ=America/Chicago \
# ...
    MED_DB_USERNAME= \
    MED_DB_PASS= \
# ...

RUN mkdir /var/cfinstall && mkdir /usr/local/cflibs

ADD ./build/libraries/ /var/cfinstall

ADD ./build/install/ /var/cfinstall

RUN cd /var/cfinstall && ls

RUN unzip /var/cfinstall/Medispan.zip -d /usr/local/cflibs \
    && cp /var/cfinstall/medispan.wkconfig.xml /usr/local/cflibs/Medispan/ \
# ...

I deleted the container and stood it up again so I could get the very first instance of the instantiation error in /usr/local/lib/serverHome/WEB-INF/cfusion/logs/exception.log

Here is what it looks like -

"Error","XNIO-1 task-1","05/18/23","07:52:52","AgencyManager","Object instantiation exception.An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor  explicitly using the init(args) method. Error : '' The specific sequence of files included or processed is: /app/index.cfm, line: 79 "
coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception.
	at coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:222)
	at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:96)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3627)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3604)
	at cfMedispan2ecfc1665728274$funcLOADCLASSIFICATIONCACHE.runFunction(/app/packages/Medispan/Medispan.cfc:79)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:288)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4175)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4155)
	at cfMedispan2ecfc1665728274$funcINIT.runFunction(/app/packages/Medispan/Medispan.cfc:16)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:609)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:835)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:641)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3549)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3524)
	at cfsessionrefresh2ecfc969640930$funcLOADAPPLICATIONCACHE.runFunction(/app/AM/cfc/sessionrefresh.cfc:67)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:609)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:835)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:641)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3549)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3524)
	at cfApplication2ecfc1572209739$funcONAPPLICATIONSTART.runFunction(/app/Application.cfc:343)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:288)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:830)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:613)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:438)
	at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:115)
	at coldfusion.runtime.AppEventInvoker.onApplicationStart(AppEventInvoker.java:238)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:418)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:162)
	at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:96)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
	at coldfusion.CfmServlet.service(CfmServlet.java:226)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:67)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.cfmlprojects.regexpathinfofilter.RegexPathInfoFilter.doFilter(RegexPathInfoFilter.java:47)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:67)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at runwar.undertow.SSLClientCertHeaderHandler.handleRequest(SSLClientCertHeaderHandler.java:144)
	at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
	at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:275)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:255)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79)
	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1423)
	at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:216)
	... 111 more
Caused by: java.lang.ExceptionInInitializerError
	at medispan.dib.Navigation.<init>(Unknown Source)
	... 116 more
Caused by: java.lang.NullPointerException
	at medispan.logging.LogWriter.<clinit>(Unknown Source)
	... 117 more

Sorry for the delay, we’ve been busy at our Into The Box conference happening right now. The actual root error is right there. I have no idea why it’s happening, but there it is. I would guess perhaps a required jar is still missing, but the error is a NPE so it’s hard to say.

I don’t know what Java library you’re trying to use and I can’t find anything at all online regarding the medispan class in your error, so you’ll need to reach out to their support to ask them why their library is throwing a null pointer exception when you try to create it.

Thanks for the feedback. I probably won’t be able to put much time into troubleshooting this in the near future. It is an undocumented third party library to me too. Maybe when I do have time again, I could try to recreate the issue with just two jar files with a dependency between them and see if I get the same behavior.