apache / incubator-kie-kogito-runtimes

Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
Apache License 2.0
533 stars 205 forks source link

Kogito MapMessageMarshaller throws an error java.util.Map is abstract; cannot be instantiated for Map Property in class #3176

Open a-kshesh opened 1 year ago

a-kshesh commented 1 year ago

Describe the bug

I am using the process-postgresql-persistence-quarkus example on my MAC to showcase my problem and in there for Address.java class, I changed String city; to private Map<String, String> city; which leads to an error as

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step org.kie.kogito.quarkus.processes.deployment.ProcessesAssetsProcessor#postGenerationProcessing threw an exception: org.kie.memorycompiler.KieMemoryCompilerException: [org/kie/kogito/app/MapMessageMarshaller.java (32:31) : java.util.Map is abstract; cannot be instantiated]
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:137)
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:105)
        at org.drools.drl.quarkus.util.deployment.DroolsQuarkusResourceUtils.compileGeneratedSources(DroolsQuarkusResourceUtils.java:155)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.generatePersistenceInfo(WorkflowProcessor.java:216)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.postGenerationProcessing(WorkflowProcessor.java:181)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:335)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:252)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:60)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:86)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:447)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:59)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:149)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:104)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step org.kie.kogito.quarkus.processes.deployment.ProcessesAssetsProcessor#postGenerationProcessing threw an exception: org.kie.memorycompiler.KieMemoryCompilerException: [org/kie/kogito/app/MapMessageMarshaller.java (32:31) : java.util.Map is abstract; cannot be instantiated]
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:137)
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:105)
        at org.drools.drl.quarkus.util.deployment.DroolsQuarkusResourceUtils.compileGeneratedSources(DroolsQuarkusResourceUtils.java:155)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.generatePersistenceInfo(WorkflowProcessor.java:216)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.postGenerationProcessing(WorkflowProcessor.java:181)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

        at io.quarkus.builder.Execution.run(Execution.java:123)
        at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
        at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:160)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:331)
        ... 9 more
Caused by: org.kie.memorycompiler.KieMemoryCompilerException: [org/kie/kogito/app/MapMessageMarshaller.java (32:31) : java.util.Map is abstract; cannot be instantiated]
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:137)
        at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:105)
        at org.drools.drl.quarkus.util.deployment.DroolsQuarkusResourceUtils.compileGeneratedSources(DroolsQuarkusResourceUtils.java:155)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.generatePersistenceInfo(WorkflowProcessor.java:216)
        at org.kie.kogito.quarkus.workflow.deployment.WorkflowProcessor.postGenerationProcessing(WorkflowProcessor.java:181)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Expected behavior

Mapmarshller throws that java.util.Map is abstract; cannot be instantiated. I tried to instantiate it private Map<String, String> city; = new HashMap<String,String>(); but it throws the same error. Kindly please advise on what needs to be done.

Thanks.

Actual behavior

I expect it to accept the Map abstract data type.

How to Reproduce?

Reproducer:

process-postgresql-persistence-quarkus example to showcase my problem and in there for Address.java class, I changed private String city; to private Map<String, String> city; If I remove the kogito-addons-quarkus-persistence-jdbc dependency from the project then it works as expected.

Output of uname -a or ver

No response

Output of java -version

openjdk version "17.0.7" 2023-04-18

GraalVM version (if different from Java)

No response

Kogito version or git rev (or at least Quarkus version if you are using Kogito via Quarkus platform BOM)

quarkus platform version 2.16.8.Final

Build tool (ie. output of mvnw --version or gradlew --version)

maven- 17

Additional information

I am not specifying the version of kogito-addons-quarkus-persistence-jdbc so I am assuming that it uses a current stable version of that.

radtriste commented 1 year ago

@a-kshesh Could you try this ?

private HashMap<String, String> city;

cc @baldimir @fjtirado @cristianonicolai

a-kshesh commented 1 year ago

@radtriste Thanks. I tried HashMap and it is working. May I know why it is not able to instantiates the Map interface or do I have to explicitly do that?

radtriste commented 1 year ago

@radtriste Thanks. I tried HashMap and it is working. May I know why it is not able to instantiates the Map interface or do I have to explicitly do that?

This was just a guess.

@mariofusco @danielezonca @tarilabs @tkobayas may help more on that

tkobayas commented 1 year ago

I tested the same and found this Java code generated internally.

package org.kie.kogito.app;

import java.io.IOException;
import org.infinispan.protostream.MessageMarshaller;

public class MapMessageMarshaller implements MessageMarshaller<java.util.Map> {

    public java.lang.Class<java.util.Map> getJavaClass() {
        return java.util.Map.class;
    }

    public String getTypeName() {
        return "org.kie.kogito.app.Map";
    }

    public java.util.Map readFrom(ProtoStreamReader reader) throws IOException {
        java.util.Map value = new java.util.Map();
        return value;
    }

    public void writeTo(ProtoStreamWriter writer, java.util.Map t) throws IOException {
    }
}

The readFrom method is generated here: https://github.com/kiegroup/kogito-runtimes/blob/1.42.0.Final/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/persistence/marshaller/AbstractMarshallerGenerator.java#L172-L173

I think the process team can look at this whether it should be fixed or is an expected behaviour. @cristianonicolai