Skip to content

GraalVM unintentionally initialized at build time error #2248

Open
@dennishendriksen

Description

@dennishendriksen

Search before asking

  • I had searched in the issues and found no similar issues.

Version

Fury v0.10.2 and GraalVM 21.0.7

Component(s)

Java

Minimal reproduce step

content of src/main/resources/META-INF/native-image/com.example/helloworld/native-image.properties:

Args = --initialize-at-build-time=com.example.helloworld.p3.FuryFactory --trace-class-initialization=com.example.helloworld.p3.FuryFactory_FooFuryCodec_0

this works when creating a native image and Foo is a record:

package com.example.helloworld.p3;

import org.apache.fury.Fury;
import org.apache.fury.config.Language;

public class FuryFactory {
    public enum Bar {X}

    public record Foo(Bar bar) {}

    public static final Fury fury;

    static {
        fury = Fury.builder().withLanguage(Language.JAVA).requireClassRegistration(true).build();
        fury.register(Bar.class, true);
        fury.register(Foo.class, true);
    }
}

but the same example does not work when Foo is a inner class:

package com.example.helloworld.p3;

import org.apache.fury.Fury;
import org.apache.fury.config.Language;

public class FuryFactory {
    public enum Bar {X}

    public static final class Foo {
        private final Bar bar;
        public Foo(Bar bar) { this.bar = bar; }
        public Bar bar() { return bar; }
    }

    public static final Fury fury;

    static {
        fury = Fury.builder().withLanguage(Language.JAVA).requireClassRegistration(true).build();
        fury.register(Bar.class, true);
        fury.register(Foo.class, true);
    }
}

What did you expect to see?

[INFO] BUILD SUCCESS

What did you see instead?

Error: Classes that should be initialized at run time got initialized during image building:
 com.example.helloworld.p3.FuryFactory_FooFuryCodec_0 was unintentionally initialized at build time. com.example.helloworld.p3.FuryFactory caused initialization of this class with the following trace: 
Error: Classes that should be initialized at run time got initialized during image building:
	at com.example.helloworld.p3.FuryFactory_FooFuryCodec_0.<clinit>(FuryFactory_FooFuryCodec_0.java:28)
	at jdk.internal.misc.Unsafe.allocateInstance(Unknown Source)
	at java.lang.invoke.DirectMethodHandle.allocateInstance(DirectMethodHandle.java:501)
	at java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(DirectMethodHandle$Holder)
	at java.lang.invoke.Invokers$Holder.invoke_MT(Invokers$Holder)
	at org.apache.fury.serializer.Serializers.createSerializer(Serializers.java:129)
	at org.apache.fury.serializer.Serializers.newSerializer(Serializers.java:104)
	at org.apache.fury.resolver.ClassResolver.createSerializer(ClassResolver.java:1232)
	at org.apache.fury.resolver.ClassResolver.getClassInfo(ClassResolver.java:1125)
	at org.apache.fury.resolver.ClassResolver.createSerializerAhead(ClassResolver.java:1240)
	at org.apache.fury.resolver.ClassResolver.register(ClassResolver.java:432)
	at org.apache.fury.Fury.register(Fury.java:169)
	at com.example.helloworld.p3.FuryFactory.<clinit>(FuryFactory.java:20)

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions