Mule 3.7.3 and Jackson 2.9.0 issues-NoSuchMethodError - java

I am having lots of issues getting Mule to work with Jackson classes. The classes present in my final library only have the following files. To eliminate the possibility of maven pulling in other jackson libraries, I create a mule project without using maven and simply pull in the bare minimum libraries. However, it is failing with NoSuchMethodError for CSVMapper().reader(MyClass) etc. and later with
Caused by: java.lang.NoSuchMethodError:
com.fasterxml.jackson.databind.JsonMappingException.<init>
(Ljava/io/Closeable;Ljava/lang/String;)V
jackson-core-2.9.0.jar
jackson-databind-2.9.0.jar
jackson-annotations-2.9.0.jar
jackson-dataformat-csv-2.9.0.jar
I get NoSuchMethodError when I call methods that are definitely in the classpath. To make matters worse the program runs fine outside of Mule.
It turns out that the following module mule-core.3.7.3 has an older version of Jackson i.e. 2.4.3. Unfortunately what works with version 2.9.0 now fails with
Too many entries: expected at most 1 (value #1 (18 chars) "20170822211046.581")
How can solve this problem?

I solved it by using the Jackson libraries provided by Mule i.e. version 2.4.3 for converted JSON to Java objects. For the CSV conversion to Map I used apache commons-csv replacing Jackson's CSVMapper.

Related

NoSuchMethodError in org.json.JSONObject after kubernetes upgrade from 1.21 to 1.23

I don't know if the kubernetes upgrade has anything to do with the problem, but it's the only change I know of between the time the application was working as expected and when it started throwing this exception.
I have some code in a Spring Boot app that adds a List<Object> to a JSONObject. The line looks like this:
jsonObject.put("some_name", someList);
This code hasn't been touched in a year, but suddenly started throwing this exception after a k8s upgrade from 1.21 to 1.23:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
[...]
Caused by: java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at com.example.service.MyClass.convertToJson(MyClass.java:109)
The k8s upgrade also included a change from Java 17.0.5+8 to Java 17.0.6+10, but everything runs as expected locally using both of those JDK versions.
I ran a mvn dependency tree -Dverbose and couldn't find anything weird there either. These were the only entries that had to do with json.
org.json:json:jar:20220320
org.springframework.boot:spring-boot-starter-json:jar:2.6.4
I'm out of ideas for what might be causing this issue, so any suggestions on what to look at next are welcome.
It could be that the version of org.json:json included in your project is out of date, and doesn't include the put(String, Collection) method you're trying to use. Try updating this dependency to a more recent version and seeing if that resolves the issue. It's also possible there are some other dependencies in your project which conflict with org.json:json or override it with an older version - check for any similarly named libraries (e.g., json-simple instead of org.json). You may also want to check the version of Spring Boot you're using, as this might be incompatible with the org.json library you're trying to use.

Does Hibernate 4 with ehcache require ehcache-core library?

I am attempting to upgrade an appliaction from Hibernate 3 to Hibernate 4. The application uses ehcache.
When upgrading to Hibernate 4.2.0.Final I added a dependency on hibernate-ehcache-4.2.0.Final as suggested.
When I started up the application I received the following error:
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion
According to http://www.javacraft.org/2012/03/migrate-to-hibernate-4-ehcache.html I should remove the dependency on ehcache-core and only use the hibernate provided jar to resolve this error.
Now, if I follow these instructions and remove this dependency my application which uses the net.sf.ehcache.CacheManager no-longer compiles.
// For example, this no-longer works
CacheManager manager = CacheManager.getInstance();
So my question is, can I use both libraries and continue working as before (Without updating the app), or do I have to change the app, in which case does hibernate-ehcache even provide the functionality required to access the cache?
When using Hibernate 4 you have to use the org.hibernate packaged classes.
The net.sf.ehcache ones are target at Hibernate 3.
Form 4 they have ported to 4 within the Hibernate repo directly (which is the most sensible thing in our opinion).
So using org.hibernate.cache.ehcache.EhCacheRegionFactory should solve your problem.
Check if there any .properties file in your project like hsqlDatabaseConfig.properties, try to update the property as below
sessionFactory.hibernateProperties = hibernate.cache.use_second_level_cache=true\n\
hibernate.cache.use_query_cache=true\n\
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.internal.EhcacheRegionFactory\n\

Compatiblity Issue of asm 3.1 and org.eclipse.persistence.asm-2.3.2.jar (jersey-moxy 1.15)

A similar problem as in Compatibility Issue of ASM 3.1 and HIbernate and JAX-RS
seems to have hit me:
my Jersey / JPA based rest application which also uses jersey-moxy (version 1.15 of jersey) throws an error:
Caused by: java.lang.NoSuchMethodError: org.eclipse.persistence.internal.libraries.asm.ClassReader.accept(Lorg/eclipse/persistence/internal/libraries/asm/ClassVisitor;[Lorg/eclipse/persistence/internal/libraries/asm/Attribute;Z)V
My maven dependency list shows:
asm-3.1.jar
jersey-moxy-1.15.jar
org.eclipse.persistence.asm-2.3.2.jar
if i remove jersey-moxy 1.15 from the dependency the problem goes away but then I can't use the extra MOXy features.
If exclude the org.eclipse.persistence.asm dependency i get:
Internal Exception: java.lang.SecurityException: class "org.eclipse.persistence.sessions.factories.SessionManager"'s signer information does not match signer information of other classes in the same package
What would be a solution to this situation?
This issue isn't the same as Compatibility Issue of ASM 3.1 and HIbernate and JAX-RS. EclipseLink specifically ships a repackaged version of ASM to specifically avoid this issue.
I'm not familiar with the jersey-moxy-1.15.jar (could you provide additional info on this one?). MOXy requires the following bundles:
org.eclipse.persistence.moxy_2.4.1.v20121003-ad44345.jar
org.eclipse.persistence.core_2.4.1.v20121003-ad44345.jar
org.eclipse.persistence.asm_3.3.1.v201206041142.jar
If you are using MOXy for JSON binding (see http://blog.bdoughan.com/2012/05/moxy-as-your-jax-rs-json-provider.html), then you also require the following bundle:
org.eclipse.persistence.antlr_3.2.0.v201206041011.jar

Modify Enunciate generated configuration file to use the latest jackson library for CXF

Enunciate generates the cxf-jaxrs-servlet.xml file automatically and specifies: org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider as the JAX-RS provider. This class has changed to com.fasterxml.jackson.jaxrs.JacksonJaxbJsonProvider in the latest Jackson library. How can I make Enunciate specify the new class as the JSON provider in the automatically generated file? Or can I make Enunciate to use a user provided XML file?
I had a similar issue and am using Maven with Spring. I was able to solve this by using the maven replacer plugin and setting it to overwrite the org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider in jaxrs:providers and replacing it with com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.
Unfortunately, there's not a good way to do that at the moment. We're tracking support for Jackson 2 at ENUNCIATE-719.

Jackson + Tomcat - java.lang.VerifyError: Cannot inherit from final class

I have a Java webservice running in Tomcat 6 which accepts JSON input. I am trying to use Jackson ObjectMapper to parse the input json. But when initializing the ObjectMapper object I am getting this error
16:08:13,616 ERROR [[jersey]] Servlet.service() for servlet jersey threw exception
java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2733)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1124)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at com.test.project.offline.ws.WsApiResource.updateData(WsApiResource.java:169)
.......
At line 169 I have this ObjectMapper mapper = new ObjectMapper();
When calling com.test.project.offline.ws.WsApiResource.updateData() method locally in a unit test it works without any error.
Kindly help me in fixing this. I am using Jackson 1.8.4 and tomcat 6.
UPDATE: Fixed the issue. Problem was a different version of jackson in the dependency tree. Excluding it fixed the problem.
I also had the same issue with Apache Lucene. I had lucene-core-3.6.0.jar and lucene-core-3.5.0.jar in my /WEB-INF/lib folder. Removing one or the other also fixed my problem. It must be a versioning issue.
I had the same issue with Apache Solr, and it was resolved by deleting my ~/.m2 cache.
This issue was also caused by specifying the wrong version of a dependency in my pom.xml file, where another package was automatically downloading another version.
Maven really should have some sort of conflicting versions of dependency resolution scheme...
The same for me - my ejb3 application uses jackson-all-1.9.4 - and my glassfish container (v2.1) contains a lib/jackson-asl-0.9.4.jar:
java.lang.VerifyError: Cannot inherit from final class
Now, I have replaced jackson-all with gson.
Thanks,
Danny
Neil has a great answer to this question. However, aside from your M2 cache, check if you're a complete DUMMY like I WAS and ensure your POM doesn't include two packages where the same Final class is declared. Google API's are notorious for cross including classes in their API Jars. Ensure you delete EVERYTHING you don't need!

Categories