/** * Finalises the {@link Event} and returns it. * <p> * This operations will automatically set the missing values and make the mutable values immutable. * * @return an immutable event. */ public synchronized Event build() { if (alreadyBuilt) throw new IllegalStateException("A message can't be built twice"); autoSetMissingValues(event); makeImmutable(event); // Lock it only when everything has been set, in case of exception it should be possible to try to build again. alreadyBuilt = true; return event; }