-
Bug
-
Resolution: Done
-
Major
-
0.6.1
-
None
-
2020 Week 01-03 (from Dec 30)
REST endpoint class for single bind variable query (e.g. "FindAdultNames" of drools-quarkus-unit-example) throws ClassCastException depending on its bind variable name.
2019-12-24 14:02:54,429 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-worker-thread-1) HTTP Request to /find-adult-names failed, error id: 51e3ea48-4b9f-41f4-8686-65f47dc98087-1: org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException: org.kie.kogito.queries.Person cannot be cast to java.lang.String at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106) at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372) at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:209) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:252) at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:153) at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:363) at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:156) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:238) at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73) at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:118) at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.lambda$handle$0(VertxRequestHandler.java:74) at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassCastException: org.kie.kogito.queries.Person cannot be cast to java.lang.String at org.kie.kogito.queries.AdultUnitQueryFindAdultNamesEndpoint.toResult(AdultUnitQueryFindAdultNamesEndpoint.java:45) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.kie.kogito.queries.AdultUnitQueryFindAdultNamesEndpoint.executeQuery(AdultUnitQueryFindAdultNamesEndpoint.java:32) ...
It depends on hashCode created from the name so you can reproduce the issue by changing the name several times. In my local environment, I reproduce the issue with "$name1".
RuleUnitQuery.drl
query FindAdultNames /persons[ adult, $name1 : name ] end
In the generated toResult() method, the 'tuple' contains a Person object as well so if the Person object is picked first, it throws ClassCastException.
public class AdultUnitQueryFindAdultNamesEndpoint { ... private java.lang.String toResult(Map<String, Object> tuple) { return (java.lang.String) tuple.values().iterator().next(); } }