Source:
<code>public void handleException(final String jobName, final Throwable cause) { if (null == dingtalkConfiguration) { dingtalkConfiguration = DingtalkEnvironment.getInstance().getDingtalkConfiguration(); } HttpPost httpPost = new HttpPost(getUrl()); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(dingtalkConfiguration.getConnectTimeout()) .setSocketTimeout(dingtalkConfiguration.getReadTimeout()).build(); httpPost.setConfig(requestConfig); String paramJson = getParamJson(getMsg(jobName, cause)); StringEntity entity = new StringEntity(paramJson, StandardCharsets.UTF_8.name()); entity.setContentEncoding(StandardCharsets.UTF_8.name()); entity.setContentType("application/json"); httpPost.setEntity(entity); CloseableHttpResponse response = httpclient.execute(httpPost); <START> try { int status = response.getStatusLine().getStatusCode(); if (HttpURLConnection.HTTP_OK == status) { JsonObject resp = GsonFactory.getGson().fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class); if (!"0".equals(resp.get("errcode").getAsString())) { log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: {}", jobName, resp.get("errmsg").getAsString(), cause); } else { log.error("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", jobName, cause); } } else { log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: Unexpected response status: {}", jobName, status, cause); } } finally { response.close(); } <END> }</code><technical_language>CloseableHttpResponse implement AutoCloseable. Replace finally try-with-resources</technical_language>

Target:
public void handleException(final String jobName, final Throwable cause) { if (null == dingtalkConfiguration) { dingtalkConfiguration = DingtalkEnvironment.getInstance().getDingtalkConfiguration(); } HttpPost httpPost = new HttpPost(getUrl()); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(dingtalkConfiguration.getConnectTimeout()) .setSocketTimeout(dingtalkConfiguration.getReadTimeout()).build(); httpPost.setConfig(requestConfig); String paramJson = getParamJson(getMsg(jobName, cause)); StringEntity entity = new StringEntity(paramJson, StandardCharsets.UTF_8); entity.setContentEncoding(StandardCharsets.UTF_8.name()); entity.setContentType("application/json"); httpPost.setEntity(entity); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { int status = response.getStatusLine().getStatusCode(); if (HttpURLConnection.HTTP_OK == status) { JsonObject resp = GsonFactory.getGson().fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class); if (!"0".equals(resp.get("errcode").getAsString())) { log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: {}", jobName, resp.get("errmsg").getAsString(), cause); } else { log.error("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", jobName, cause); } } else { log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: Unexpected response status: {}", jobName, status, cause); } } catch (IOException ex) { log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of", jobName, ex); } }