Uploaded image for project: 'Kogito'
  1. Kogito
  2. KOGITO-832

REST endpoint class for single bind variable query throws ClassCastException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 0.7.0
    • 0.6.1
    • Core Engine
    • None
    • Hide
      • cd kogito-examples/drools-quarkus-unit-example
      • Edit RuleUnitQuery.drl to change the variable name for 'FindAdultNames'. Start from "$name1".
        query FindAdultNames
            /persons[ adult, $name1 : name ]
        end
        
      • mvn clean package quarkus:dev -DskipTests
      • Send a request with curl:
        curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"adultAge":18,"persons":[{"name":"Mario","age":45,"adult":false},{"name":"Marilena","age":47,"adult":false},{"name":"Sofia","age":7,"adult":false}]}' http://localhost:8080/find-adult-names
        
      • If the issue doesn't reproduce, change the name to "$name2", "$name3"... you will hit the issue within several tries.

      You can also confirm the error with QueryTest.

      mvn clean test
      
      Show
      cd kogito-examples/drools-quarkus-unit-example Edit RuleUnitQuery.drl to change the variable name for 'FindAdultNames'. Start from "$name1". query FindAdultNames /persons[ adult, $name1 : name ] end mvn clean package quarkus:dev -DskipTests Send a request with curl: curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"adultAge":18,"persons":[{"name":"Mario","age":45,"adult":false},{"name":"Marilena","age":47,"adult":false},{"name":"Sofia","age":7,"adult":false}]}' http://localhost:8080/find-adult-names If the issue doesn't reproduce, change the name to "$name2", "$name3"... you will hit the issue within several tries. You can also confirm the error with QueryTest. mvn clean test
    • 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();
          }
      }
      

            mfusco@redhat.com Mario Fusco
            rhn-support-tkobayas Toshiya Kobayashi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: