eclipse-ee4j / eclipse-ee4j/expressly
Better Message for Invalid + Operation
- Dominant language
- Java
- Stars
- 15
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
I tried to use EL to access the `Optional` in a record.
```java
public record PhoneNumber(String countryCode, String number) {
}
```
And the `Customer`:
```java
public record Customer(
String firstName,
String lastName,
Optional phoneNumber,
EmailAddress[] emailAddresses,
Address address
) {
}
```
And evaluate the following expression.
```
String phoneNumber = elProcessor.eval("customer.phoneNumber.map(t-> t.countryCode+t.number).orElse('NotFound')");
System.out.println(phoneNumber);
```
It throws an exception,
```bash
java.lang.ClassCastException: class java.lang.Long cannot be cast to
class java.lang.String (java.lang.Long and java.lang.String are in
module java.base of loader 'bootstrap')
```
**But there is no `Long` type field in EL expression**.
As suggested by @OndroMih, it is better to show a message to indicate what is wrong, which will help developers to locate the issues quickly.
```bash
customer.phoneNumber.map(t-> t.countryCode[>>> + ]t.number).orElse('NotFound')
```
BTW: Replace the `map()` function with `map(t -> t.contryCode.concat(t.number))`, and it works.
Contributor guide
Assessment
This issue has not been assessed yet.