If you’re using Java 8 or higher, you can utilize Optional to handle potential null values more gracefully.
String customerId = Optional.ofNullable(user.getCustomerId()).orElse(null);