Skip to content

Nested property type in the same package can not be accessed #23

@hantsy

Description

@hantsy

I tried to create a record type like this.

public record Customer(
        String firstName,
        String lastName,
        Optional<PhoneNumber> phoneNumber,
        ...
) {
}
record PhoneNumber(...){}

When access the phoneNumber via EL, it will throw exception like this.

Caused by: java.lang.IllegalAccessException: class jakarta.el.RecordELResolver cannot access a member of class com.example.PhoneNumber with modifiers "public"
	at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:400)
	at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:670)
	at java.base/java.lang.reflect.Method.invoke(Method.java:556)
	at jakarta.el.RecordELResolver.getValue(RecordELResolver.java:76)
	... 16 more

If I move the PhoneNumber into a standalone file and add a public modifier, it will work.

// Customer.java
public record Customer(
        String firstName,
        String lastName,
        Optional<PhoneNumber> phoneNumber,
        ...
) {
}

// PhoneNumber.java
public record PhoneNumber(...){}

The example project can be found here.

  1. Clone the project.
  2. Remove the standalone nested properties related files.
  3. Uncomment the record types in the Customer
  4. Run the test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions