Source:
<code>String getTenantId() throws IOException { if (tenantId == null) { log.debug( "Requesting tenant id"); ProxyConfiguration proxyConfig = configuration.getProxyConfiguration(); String hostname = proxyConfig.getHostname(); int port = proxyConfig.getPort(); HttpContext context = new BasicHttpContext(); HttpHost host = new HttpHost(hostname, port, "http"); HttpPost post = new HttpPost(AUTHENTICATE_URL); post.addHeader(ACCEPT, APPLICATION_JSON.toString()); String username = configuration.getZenossCredentials().getUsername(); String password = configuration.getZenossCredentials().getPassword(); if (!Strings.nullToEmpty(username).isEmpty()) { CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials( new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(username, password) ); context.setAttribute(ClientContext.CREDS_PROVIDER, provider); AuthCache cache = new BasicAuthCache(); BasicScheme scheme = new BasicScheme(); cache.put( host, scheme); context.setAttribute( ClientContext.AUTH_CACHE, cache); } <START> HttpResponse response = httpClient.execute(host, post, context); <END> int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); try { log.debug( "Tenant id request complete with status: {}", statusCode); if (statusCode >= 200 && statusCode <= 299) { Header id = response.getFirstHeader(ZenossTenant.ID_HTTP_HEADER); if (id == null) { log.warn( "Failed to get zauth tenant id after login"); throw new RuntimeException("Failed to get zauth tenant id after successful login"); } tenantId = id.getValue(); log.info("Got tenant id: {}", tenantId); } else { log.warn( "Unsuccessful response from server: {}", response.getStatusLine()); throw new IOException( "Login for tenantId failed"); } } finally { try { entity.getContent().close(); } catch( IOException ex) { log.warn( "Failed to close entity: {}", ex); } } } return tenantId; }</code><technical_language>docs explicitly a method return null check it, in a try/catch handle NPE</technical_language>

Target:
String getTenantId() throws IOException { if (tenantId == null) { log.debug( "Requesting tenant id"); ProxyConfiguration proxyConfig = configuration.getProxyConfiguration(); String hostname = proxyConfig.getHostname(); int port = proxyConfig.getPort(); HttpContext context = new BasicHttpContext(); HttpHost host = new HttpHost(hostname, port, "http"); HttpPost post = new HttpPost(AUTHENTICATE_URL); post.addHeader(ACCEPT, APPLICATION_JSON.toString()); String username = configuration.getZenossCredentials().getUsername(); String password = configuration.getZenossCredentials().getPassword(); if (!Strings.nullToEmpty(username).isEmpty()) { CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials( new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(username, password) ); context.setAttribute(ClientContext.CREDS_PROVIDER, provider); AuthCache cache = new BasicAuthCache(); BasicScheme scheme = new BasicScheme(); cache.put( host, scheme); context.setAttribute( ClientContext.AUTH_CACHE, cache); } HttpResponse response = null; try { response = httpClient.execute(host, post, context); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); log.debug( "Tenant id request complete with status: {}", statusCode); if (statusCode >= 200 && statusCode <= 299) { Header id = response.getFirstHeader(ZenossTenant.ID_HTTP_HEADER); if (id == null) { log.warn( "Failed to get zauth tenant id after login"); throw new RuntimeException("Failed to get zauth tenant id after successful login"); } tenantId = id.getValue(); log.info("Got tenant id: {}", tenantId); } else { log.warn( "Unsuccessful response from server: {}", response.getStatusLine()); throw new IOException( "Login for tenantId failed"); } } catch (NullPointerException ex) { log.warn( "npe retrieving tenantId: {}", ex); } finally { try { if ( response != null) { response.getEntity().getContent().close(); } } catch( NullPointerException | IOException ex) { log.warn( "Failed to close request: {}", ex); } } } return tenantId; }