Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to serialize java.util.Collections$SingletonSet in native mode #28466

Closed
vsevel opened this issue Oct 10, 2022 · 6 comments
Closed

Unable to serialize java.util.Collections$SingletonSet in native mode #28466

vsevel opened this issue Oct 10, 2022 · 6 comments
Labels
area/native-image env/graalvm-java17 Relating to using GraalVM native generation Java 11 kind/bug Something isn't working triage/duplicate This issue or pull request already exists

Comments

@vsevel
Copy link
Contributor

vsevel commented Oct 10, 2022

Describe the bug

I am enabling java.util.Collections$SingletonSet for serialization fro an extension with:

    @BuildStep
    void reflection(BuildProducer<ReflectiveClassBuildItem> reflection) {
        log.info("configuring reflection");
        reflection.produce(new ReflectiveClassBuildItem(true, false, false, false, AbstractSet.class.getName()));
        reflection.produce(new ReflectiveClassBuildItem(true, false, false, true, "java.util.Collections$SingletonSet"));
    }

Expected behavior

Serialization of SingletonSet should work.

Actual behavior

It fails with:

com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.util.Collections$SingletonSet (targetConstructorClass: java.util.AbstractSet). Usually adding java.util.Collections$SingletonSet to serialization-config.json fixes the problem.

How to Reproduce?

create a new extension: quarkus create extension myext
In the processor, implement:

    @BuildStep
    void reflection(BuildProducer<ReflectiveClassBuildItem> reflection) {
        log.info("configuring reflection");
        reflection.produce(new ReflectiveClassBuildItem(true, false, false, false, AbstractSet.class.getName()));
        reflection.produce(new ReflectiveClassBuildItem(true, false, false, true, "java.util.Collections$SingletonSet"));
    }

Replace MyExtResource with:

@Path("/myext")
@ApplicationScoped
public class MyextResource {

    private static final Logger log = LoggerFactory.getLogger(MyextResource.class);

    @GET
    public String hello() {

        Set<String> set = Collections.singleton("coucou");
        try {
            try (
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    ObjectOutputStream oos = new ObjectOutputStream(baos)) {

                oos.writeObject(set);
                oos.flush();

                try (
                        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
                        ObjectInputStream ois = new ObjectInputStream(bais)) {

                    Object result = ois.readObject();
                    return result.toString();
                }
            }
        } catch (Exception e) {
            log.error("serialization test error", e);
            return "KO: " + e.getMessage();
        }

    }
}

Execute: mvn install -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true

You see the exception:

[INFO] Running io.quarkiverse.myext.it.MyextResourceIT
Executing "/export/soft/appl/tmpdir/quarkus-myext/integration-tests/target/quarkus-myext-integration-tests-999-SNAPSHOT-runner -Dquarkus.http.port=8081 -Dquarkus.http.ssl-port=8444 -Dtest.url=http://localhost:8081 -Dquarkus.log.file.path=/export/soft/appl/tmpdir/quarkus-myext/integration-tests/target/quarkus.log -Dquarkus.log.file.enable=true"
__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2022-10-10 10:57:25,821 INFO  [io.quarkus] (main) quarkus-myext-integration-tests 999-SNAPSHOT native (powered by Quarkus 2.13.1.Final) started in 0.034s. Listening on: http://0.0.0.0:8081
2022-10-10 10:57:25,823 INFO  [io.quarkus] (main) Profile prod activated.
2022-10-10 10:57:25,823 INFO  [io.quarkus] (main) Installed features: [cdi, myext, resteasy, smallrye-context-propagation, vertx]
2022-10-10 10:57:27,419 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /myext failed, error id: f501bb0c-478c-460f-b6e0-069762f9c01f-1: org.jboss.resteasy.spi.UnhandledException: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.util.Collections$SingletonSet (targetConstructorClass: java.util.AbstractSet). Usually adding java.util.Collections$SingletonSet to serialization-config.json fixes the problem.
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:105)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:359)
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
        at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
        at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:151)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:91)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:564)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:833)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.util.Collections$SingletonSet (targetConstructorClass: java.util.AbstractSet). Usually adding java.util.Collections$SingletonSet to serialization-config.json fixes the problem.
        at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
        at com.oracle.svm.reflect.serialize.SerializationSupport.getSerializationConstructorAccessor(SerializationSupport.java:143)
        at jdk.internal.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:48)
        at jdk.internal.reflect.ReflectionFactory.generateConstructor(ReflectionFactory.java:463)
        at jdk.internal.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:455)
        at java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1443)
        at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:412)
        at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:384)
        at java.security.AccessController.executePrivileged(AccessController.java:169)
        at java.security.AccessController.doPrivileged(AccessController.java:318)
        at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:384)
        at java.io.ObjectStreamClass$Caches$1.computeValue(ObjectStreamClass.java:110)
        at java.io.ObjectStreamClass$Caches$1.computeValue(ObjectStreamClass.java:107)
        at java.io.ClassCache$1.computeValue(ClassCache.java:73)
        at java.io.ClassCache$1.computeValue(ClassCache.java:70)
        at java.lang.ClassValue.get(JavaLangSubstitutions.java:588)
        at java.io.ClassCache.get(ClassCache.java:84)
        at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:363)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1137)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:350)
        at io.quarkiverse.myext.it.MyextResource.hello(MyextResource.java:48)
        at io.quarkiverse.myext.it.MyextResource_ClientProxy.hello(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:568)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
        at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
        at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
        ... 17 more

Output of uname -a or ver

Linux graalvmdev.dev.biz.lodh.com 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

17

GraalVM version (if different from Java)

22.2

Quarkus version or git rev

2.13.1

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

3.8.1

Additional information

No response

@vsevel vsevel added the kind/bug Something isn't working label Oct 10, 2022
@gastaldi gastaldi added the env/graalvm-java17 Relating to using GraalVM native generation Java 11 label Oct 10, 2022
@gsmet
Copy link
Member

gsmet commented Oct 10, 2022

@vsevel could you provide a reproducer instead of instructions. That will be easier for us.

/cc @Karm @zakkak

@vsevel
Copy link
Contributor Author

vsevel commented Oct 10, 2022

here it is: https://github.com/vsevel/quarkus-issue-serial-28466
execute instructions in readme
the result of the curl should be [] (no errors)
instead it is: [KO: SerializationConstructorAccessor class not found for declaringClass: java.util.Collections$SingletonSet (targetConstructorClass: java.util.AbstractSet). Usually adding java.util.Collections$SingletonSet to serialization-config.json fixes the problem., KO: java.util.ImmutableCollections$Set12] (2 errors)

@zakkak
Copy link
Contributor

zakkak commented Oct 11, 2022

@vsevel it looks like #28431

It's fixed on main and the fix will land in 2.13.2.

@vsevel
Copy link
Contributor Author

vsevel commented Oct 12, 2022

wonderful @zakkak - thanks for looking into it. let's close this. will reopen if necessary

@vsevel vsevel closed this as completed Oct 12, 2022
@vsevel
Copy link
Contributor Author

vsevel commented Oct 12, 2022

@gsmet when do you think will 2.13.2 get produced?

@geoand geoand added the triage/duplicate This issue or pull request already exists label Oct 12, 2022
@vsevel
Copy link
Contributor Author

vsevel commented Oct 13, 2022

I confirm the issue is fixed with 2.13.2. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image env/graalvm-java17 Relating to using GraalVM native generation Java 11 kind/bug Something isn't working triage/duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants