Source:
<code>public static void main(String[] args) { final String email = "joe.coder+" + UUID.randomUUID().toString() + "@example.com"; final String groupName = "java-sdk-quickstart-" + UUID.randomUUID().toString(); final char[] password = {'P','a','s','s','w','o','r','d','1'}; ClientBuilder builder; Client client; Group group = null; User user = null; try { builder = Clients.builder(); client = builder.build(); group = GroupBuilder.instance() .setName(groupName) .setDescription("Quickstart created Group") .buildAndCreate(client); println("Group: '" + group.getId() + "' was last updated on: " + group.getLastUpdated()); user = UserBuilder.instance() .setEmail(email) .setFirstName("Joe") .setLastName("Coder") .setPassword(password) .setSecurityQuestion("Favorite security question?") .setSecurityQuestionAnswer("None of them!") .putProfileProperty("division", "Seven") .setActive(true) .buildAndCreate(client); user.addToGroup(group.getId()); String userId = user.getId(); println("User created with ID: " + userId); println("User lookup by ID: "+ client.getUser(userId).getProfile().getLogin()); println("User lookup by Email: "+ client.getUser(email).getProfile().getLogin()); UserList users = client.listUsers(); println("First user in collection: " + users.iterator().next().getProfile().getEmail()); } catch (ResourceException e) { println(e.getMessage()); e.getCauses().forEach( cause -> println("\t" + cause.getSummary())); throw e; } finally { <START> if (user != null && user.getStatus() != UserStatus.DEPROVISIONED) { user.deactivate(); } user.delete(); <END> if (group != null) { group.delete(); } } }</code><technical_language>If user is null this delete fail</technical_language>

Target:
public static void main(String[] args) { final String email = "joe.coder+" + UUID.randomUUID().toString() + "@example.com"; final String groupName = "java-sdk-quickstart-" + UUID.randomUUID().toString(); final char[] password = {'P','a','s','s','w','o','r','d','1'}; ClientBuilder builder; Client client; Group group = null; User user = null; try { builder = Clients.builder(); client = builder.build(); group = GroupBuilder.instance() .setName(groupName) .setDescription("Quickstart created Group") .buildAndCreate(client); println("Group: '" + group.getId() + "' was last updated on: " + group.getLastUpdated()); user = UserBuilder.instance() .setEmail(email) .setFirstName("Joe") .setLastName("Coder") .setPassword(password) .setSecurityQuestion("Favorite security question?") .setSecurityQuestionAnswer("None of them!") .putProfileProperty("division", "Seven") .setActive(true) .buildAndCreate(client); user.addToGroup(group.getId()); String userId = user.getId(); println("User created with ID: " + userId); println("User lookup by ID: "+ client.getUser(userId).getProfile().getLogin()); println("User lookup by Email: "+ client.getUser(email).getProfile().getLogin()); UserList users = client.listUsers(); println("First user in collection: " + users.iterator().next().getProfile().getEmail()); } catch (ResourceException e) { println(e.getMessage()); e.getCauses().forEach( cause -> println("\t" + cause.getSummary())); throw e; } finally { if (user != null) { if (user.getStatus() != UserStatus.DEPROVISIONED) { user.deactivate(); } user.delete(); } if (group != null) { group.delete(); } } }