Looking up a hostname for a given path and client ID
Just don't duplicate it:

Map&lt;Integer, Integer&gt; intermediate = mapping.get(path);
if (intermediate != null) {
    Integer localId = intermediate.get(clientId);
    if (localId != null) {
        return getHostname(path, localId);
    }
}

// log error here
return null;


Alternatively, you could throw the above into a helper function:

private Integer getLocalId(String path, int clientId)
{
    Map&lt;Integer, Integer&gt; intermediate = mapping.get(path);
    if (intermediate != null) {
        return intermediate.get(clientId);
    }
    return null;
}


And then have just the one check:

private String getAddress(final String path, final int clientId) {
    Integer localId = getLocalId(path, clientId);
    if (localId == null) {
        // error
        return null;
    }

    return getHostname(path, localId);
}