Given the following code.
@Getter
@Builder(builderClassName = "Builder", buildMethodName = "build")
public final class BusinessEvent implements BusinessPayload {
private String action, duration, outcome, provider, trackId, sequence;
@lombok.Builder.Default private Optional<String> brand, vin, externalTrackId, code = Optional.empty();
@lombok.Builder.Default private Optional<BusinessEventError> eventError = Optional.empty();
static class Builder {
BusinessEvent build() throws MissingRequiredValueException {
// Custom validation
return new BusinessEvent(action, duration, outcome, provider, trackId, sequence, brand, vin, externalTrackId, code, eventError);
}
}
}
I get the error
java: non-static variable eventError cannot be referenced from a static context
Somehow Optional values are not handled correctly by lombok in this case? I see the same problem in all my builders. This is not shown as an issue by intellij plugin but only when I try to build.
I know you should not use optional as field values but in this case it make the API much clearer and the builder will not get serialized anyways, we have DTOs for that.