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.
- Clone the project.
- Remove the standalone nested properties related files.
- Uncomment the record types in the
Customer
- Run the test.
I tried to create a record type like this.
When access the
phoneNumbervia 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 moreIf I move the
PhoneNumberinto a standalone file and add apublicmodifier, it will work.The example project can be found here.
Customer