quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.36k stars 2.56k forks source link

Support @RequestScoped Java records #9187

Open arvidvillen opened 4 years ago

arvidvillen commented 4 years ago

Description It would be nice if you could use Java 14 records in CDI/arc producer methods. Currently you get the following (build time) exception:

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: It is not possible to add a synthetic constructor with no parameters to the unproxyable return type of: PRODUCER METHOD bean [types=[java.lang.Record, java.lang.Object, org.acme.ExampleRecord], qualifiers=[@Default, @Any], target=org.acme.ExampleRecord produceExampleRecord(), declaringBean=org.acme.ExampleRecordProducer]
    at io.quarkus.arc.processor.Beans.validateBean(Beans.java:739)
    at io.quarkus.arc.processor.BeanInfo.validate(BeanInfo.java:355)
    at io.quarkus.arc.processor.BeanDeployment.validateBeans(BeanDeployment.java:1027)
    at io.quarkus.arc.processor.BeanDeployment.validate(BeanDeployment.java:329)
    at io.quarkus.arc.processor.BeanProcessor.validate(BeanProcessor.java:144)
    at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:359)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:931)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    at java.base/java.lang.Thread.run(Thread.java:832)
    at org.jboss.threads.JBossThread.run(JBossThread.java:479)

Example Example project using a record producer: https://github.com/arvidvillen/quarkus-producer-records

Implementation ideas Im not sure this is technically possible (or if it’s a good idea) so feel free to reject this issue if you don’t want to support it.

geoand commented 4 years ago

I think it should work if you try using @Singleton scope.

Can you give it a try?

I'm not sure what we can do about the other scopes. It would probably need investigation.

arvidvillen commented 4 years ago

Indeed @Singleton works 😊 However, most of my use cases are @RequestScoped scoped.

nimo23 commented 4 years ago

I think @Singleton works because it does not use proxies..is there a performance benefit (speed, memory) when using @ApplicationScoped instead of @Singleton?

diversit commented 1 month ago

Any process on this? Why is a record not allowed for request scoped objects? How great would a record be for this: immutable so for another request guaranteed a new instance. When using a POJO instead, would there not be a potential issue that the POJO may contain property values of another request?