ClassCastException occured on Solver.solve in spring boot

640 views
Skip to first unread message

常照亮

unread,
Jan 23, 2019, 9:43:17 PM1/23/19
to OptaPlanner development
Thank you.
 Now that I know that this error is related to spring-boot-devtools, and that the error will not occur if spring-boot-devtools is removed, I wonder if there is a solution without removing spring-boot-devtools

 
java.lang.ClassCastException: com.bugu.queen.persistence.mongodb.domain.period.PeriodSolution cannot be cast to com.bugu.queen.persistence.mongodb.domain.period.PeriodSolution
 at com
.bugu.queen.service.solver.score.PeriodScoreCalculator.calculateScore(PeriodScoreCalculator.groovy)
 at org
.optaplanner.core.impl.score.director.easy.EasyScoreDirector.calculateScore(EasyScoreDirector.java:60)
 at org
.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:69)
 at org
.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:76)
 at org
.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:210)
 at org
.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:190)
 at org
.optaplanner.core.api.solver.Solver$solve.call(Unknown Source)
 at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
 at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
 at com
.bugu.queen.service.CourseScheduleService.solve(CourseScheduleService.groovy:619)
 at com
.bugu.queen.service.CourseScheduleService$$FastClassBySpringCGLIB$$6b1e6706.invoke(<generated>)
 at org
.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
 at org
.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org
.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 at com
.bugu.queen.aop.logging.LoggingAspect.logAround(LoggingAspect.java:85)
 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:498)
 at org
.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 at org
.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 at org
.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
 at com
.bugu.queen.service.CourseScheduleService$$EnhancerBySpringCGLIB$$d38767e5.solve(<generated>)
 at com
.bugu.queen.service.CourseScheduleService$solve.call(Unknown Source)
 at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
 at com
.bugu.queen.web.rest.management.LectureArrangePlanResource.save(LectureArrangePlanResource.groovy:425)
 at com
.bugu.queen.web.rest.management.LectureArrangePlanResource$$FastClassBySpringCGLIB$$a0764314.invoke(<generated>)
 at org
.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
 at org
.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org
.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 at com
.bugu.queen.aop.logging.LoggingAspect.logAround(LoggingAspect.java:85)
 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:498)
 at org
.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 at org
.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 at org
.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:69)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
 at org
.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
 at org
.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
 at com
.bugu.queen.web.rest.management.LectureArrangePlanResource$$EnhancerBySpringCGLIB$$c492d109.save(<generated>)
 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:498)
 at org
.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
 at org
.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
 at org
.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
 at org
.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)
 at org
.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
 at org
.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
 at org
.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
 at org
.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
 at org
.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
 at org
.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
 at javax
.servlet.http.HttpServlet.service(HttpServlet.java:707)
 at org
.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
 at javax
.servlet.http.HttpServlet.service(HttpServlet.java:790)
 at io
.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
 at com
.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:111)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
 at org
.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
 at org
.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at com
.bugu.queen.security.jwt.JWTFilter.doFilter(JWTFilter.java:85)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at org
.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org
.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
 at org
.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
 at org
.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
 at org
.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:155)
 at org
.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:123)
 at org
.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io
.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org
.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
 at org
.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at io
.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 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:65)
 at io
.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
 at io
.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
 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.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
 at io
.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119)
 at io
.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
 at io
.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
 at io
.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
 at io
.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
 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.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
 at io
.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
 at io
.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
 at io
.undertow.server.Connectors.executeRootHandler(Connectors.java:336)
 at io
.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
 at java
.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java
.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at java
.lang.Thread.run(Thread.java:748)

Geoffrey De Smet

unread,
Jan 24, 2019, 3:17:22 AM1/24/19
to optapla...@googlegroups.com

spring-boot-devtools does some classloader magic
and this seems to give problems even with easy score calculation.

Although some stackoverflow questions seem to indicate that this happens when you got the same class twice in the spring-boot classpath.
To confirm that, put an exception breakpoint on that ClassCastException and use class.getPackage() on both
and then dig down deeper in there until you find the file URL where they both classes come from.
Report those 2 file URL's here.


With kind regards,
Geoffrey De Smet

--
You received this message because you are subscribed to the Google Groups "OptaPlanner development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optaplanner-d...@googlegroups.com.
To post to this group, send email to optapla...@googlegroups.com.
Visit this group at https://groups.google.com/group/optaplanner-dev.
For more options, visit https://groups.google.com/d/optout.

常照亮

unread,
Jan 28, 2019, 12:12:45 AM1/28/19
to OptaPlanner development

Thank you for answering my question
The packages of the two objects are the same : package com.bugu.queen.persistence.mongodb.domain.period.
在 2019年1月24日星期四 UTC+8下午4:17:22,Geoffrey De Smet写道:

Geoffrey De Smet

unread,
Jan 28, 2019, 4:24:37 AM1/28/19
to optapla...@googlegroups.com

That doesn't guarantee that they come from the same file url.
You might have the same jar twice on in file system (potentially in different versions) and both were added to your classpath.

When doing runtime debugging, it's possible to ask each Package instance of where on the filesystem it comes from.
You get something like: "file:///foo/bar-1.2.0.jar" for both of them, and they might differ.
Or you could check if they use the same ClassLoader.

With kind regards,
Geoffrey De Smet

Geoffrey De Smet

unread,
Jan 31, 2019, 5:20:12 AM1/31/19
to optapla...@googlegroups.com

With kind regards,
Geoffrey De Smet

On 24/01/2019 03:43, 常照亮 wrote:
Reply all
Reply to author
Forward
0 new messages