question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wrong classLoader usage

See original GitHub issue

Hello,

we are using JMapper 1.6.1.CR1 in a Spring Boot Environment. We have a controller with a method like this:

public List<CampaignGroupDTO> getByClientId(@RequestParam final long clientId, @RequestParam final boolean withCampaigns) {
                JMapper<CampaignGroupDTO, CampaignGroup> mapper = new JMapper<>(CampaignGroupDTO.class, CampaignGroup.class);
		List<CampaignGroupDTO> dtos = new ArrayList<>();
		this.campaignGroupService.findAllWithCampaigns(clientId).forEach(c -> dtos.add(mapper.getDestination(c)));
		return dtos;
	}

Calling getByClientId() the first time works fine, and also the mapping does what we expect it should. But calling the method twice raises following exception:

com.googlecode.jmapper.exceptions.JMapperException: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader): attempted duplicate class definition for name: “demycompanycampaigngroupdtoCampaignGroupDTOdemycompanycampaigngroupentityCampaignGroup” at com.googlecode.jmapper.config.JmapperLog.ERROR(JmapperLog.java:46) at com.googlecode.jmapper.JMapper.<init>(JMapper.java:437) at com.googlecode.jmapper.JMapper.<init>(JMapper.java:373) at com.googlecode.jmapper.JMapper.<init>(JMapper.java:360) at de.mycompany.campaigngroup.controller.CampaignGroupController.getByClientId(CampaignGroupController.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:208) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader): attempted duplicate class definition for name: “demycompanycampaigngroupdtoCampaignGroupDTOdemycompanycampaigngroupentityCampaignGroup” at javassist.ClassPool.toClass(ClassPool.java:1170) at javassist.ClassPool.toClass(ClassPool.java:1113) at javassist.ClassPool.toClass(ClassPool.java:1071) at javassist.CtClass.toClass(CtClass.java:1264) at com.googlecode.jmapper.generation.JavassistGenerator.generate(JavassistGenerator.java:90) at com.googlecode.jmapper.generation.MapperGenerator.generateMapperClass(MapperGenerator.java:74) at com.googlecode.jmapper.generation.MapperBuilder.generate(MapperBuilder.java:88) at com.googlecode.jmapper.JMapper.createMapper(JMapper.java:450) at com.googlecode.jmapper.JMapper.<init>(JMapper.java:432) … 63 more Caused by: java.lang.LinkageError: loader (instance of org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader): attempted duplicate class definition for name: “demycompanycampaigngroupdtoCampaignGroupDTOdemycompanycampaigngroupentityCampaignGroup” at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.lang.ClassLoader.defineClass(ClassLoader.java:642) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at javassist.ClassPool.toClass2(ClassPool.java:1183) at javassist.ClassPool.toClass(ClassPool.java:1164)

Any help would be appreciated 😃

Jan

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:28 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
avurrocommented, Nov 28, 2016

good news! JMapper is more robust thanks to you! close the issue when you are confident 👍

1reaction
avurrocommented, Nov 23, 2016

ok Jan, the important thing is that you are not locked. In the meantime i will find a solution for that too 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClassLoader loading wrong file - java - Stack Overflow
the code snippet will use the class loader that loaded this class to find the version.txt file. if the file exists in the...
Read more >
Classloader-Releated Memory Issues - Dynatrace
Throughout this ebook chapter, we will cover some of the most common classloader-related memory issues, and how to identify, and solve them. Learn...
Read more >
QueuedThreadPool sets wrong Classloader for use in quarkus
This classloader can not load classes from the current project. Correct classloader should be obtained by Thread.currentThread().
Read more >
Class loading exceptions - IBM
The application may be incorrectly using the class loader application programming interface (API ). For example, the class name is incorrect, the ...
Read more >
Class Loaders in Java - Baeldung
Class loaders are responsible for loading Java classes dynamically to the JVM (Java Virtual Machine) during runtime.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found