Skip to content

Unable to generate random values to record type #514

@garcia-jj

Description

@garcia-jj

I'm trying to use records with easy-random 5.0.0, but I was unable to run properly, as you can see in the following code.

public record MyRecord(Long b, String a) {

}

And the runner is

final var testing = new EasyRandom().nextObject(MyRecord.class);

And I got this error:

org.jeasy.random.ObjectCreationException: Unable to create a random instance of type class foo.bar.MyRecord


Caused by: java.lang.IllegalAccessException: Can not set final java.lang.Long field foo.bar.MyRecord.a to java.lang.Long
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
	at java.base/jdk.internal.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:79)

My Java version

java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

Thank U

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions