2

I am using Jackson Core version 2.8.3, but why do I keep getting java.lang.NoSuchMethodError? I am not using any other Jackson's modules, just the core (streaming) API

Object[] result = imageGenerator.generate(lowerBound, upperBound, fileNames);
MWNumericArray array = (MWNumericArray)result[0];
try (Writer writer = response.getWriter();
     JsonGenerator generator = res.getJsonFactory().createGenerator(writer)) {

     generator.writeStartObject();
         generator.writeFieldName("dimension");
         generator.writeArray(array.getDimensions(), 0, 2); // java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeArray([III)V

         int[] pixels = array.getIntData();
         generator.writeFieldName("pixels");
         generator.writeArray(pixels, 0, pixels.length);
     generator.writeEndObject();
}

Stack trace

at servlet.IonImageGeneratorServlet.processRequest(IonImageGeneratorServlet.java:48)
at servlet.IonImageGeneratorServlet.doGet(IonImageGeneratorServlet.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Trash Can
  • 6,608
  • 5
  • 24
  • 38

1 Answers1

11

This error almost always (99% of the time) indicates that you built your code against one library version but the deployment environment has a different version that is missing that method. Your code compiled correctly but when loaded in your deployment environment the JVM tried to link it with the version of the library class it has available and couldn't find the method.

The solution is to make sure you have the same version of the library in both your development environment and your deployment server.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • 1
    Yeah man, I hit "Clean and Build" in Netbeans, but I am still getting the same error. I think your linked answer might be the cause of my problem because, I upgraded from 2.0.0 to 2.8.3 couple weeks ago, and the 2.0.0 version does not have the method. But I don't know why I am still getting the same error even though clicking "Clean and Build" in Netbeans – Trash Can Oct 14 '16 at 20:40
  • 1
    Because in NetBeans you have the right version, but in your Tomcat server you still have the old version. – Jim Garrison Oct 14 '16 at 20:50
  • I run with the the option `-verbose:class` enabled, it showed the version `2.8.3` was loaded – Trash Can Oct 14 '16 at 20:52
  • So, I created a regular Java class with a main method and use the method that has been causing the error, and it runs fine. But if I run the web app on payara, it gives me that error. Do you know how to force payara to use the latest version of the library? – Trash Can Oct 14 '16 at 21:02
  • Ask Payara support? – Jim Garrison Oct 18 '16 at 20:43
  • And what do I do when I'm building and running in the same environment? I'm not even sure where to look. It runs fine in IntelliJ, but fails when run from the command line. – MiguelMunoz Sep 18 '18 at 05:54
  • Those two are not "the same environment". IntelliJ controls the classpath but on the command line YOU control the classpath based on the `-cp` option. – Jim Garrison Sep 18 '18 at 08:25