为什么会出现这种执行顺序 ?

问题遇到的现象和发生背景

img


执行顺序如图所示(2为方法名),第一次请求为200,没有进五号哪个if
我考虑是不是2是又调用了一次这个方法,但是通过debug发现再次运行到5时是没有statuscode等参数的,而且debug时他是直接跳到5的

问题相关代码
private void autoUpdateCert() throws IOException, GeneralSecurityException {
        CloseableHttpClient httpClient = WechatPayHttpClientBuilder.create().withCredentials(this.credentials).withValidator((Validator)(this.verifier == null ? (responsex) -> {
            return true;
        } : new WechatPay2Validator(this.verifier))).build();

        try {
            HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/certificates");
            httpGet.addHeader("Accept", "application/json");
            CloseableHttpResponse response = httpClient.execute(httpGet);

            try {
                int statusCode = response.getStatusLine().getStatusCode();
                String body = EntityUtils.toString(response.getEntity());
                if (statusCode != 200) {
                    log.warn("Auto update cert failed, statusCode = " + statusCode + ",body = " + body);
                    return;
                }

                List<X509Certificate> newCertList = this.deserializeToCerts(this.apiV3Key, body);
                if (!newCertList.isEmpty()) {
                    this.verifier = new CertificatesVerifier(newCertList);
                    return;
                }

                log.warn("Cert list is empty");
            } finally {
                response.close();
            }
        } finally {
            httpClient.close();
        }

这是调用他的方法:

public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, int minutesInterval) {
        this.lock = new ReentrantLock();
        this.credentials = credentials;
        this.apiV3Key = apiV3Key;
        this.minutesInterval = minutesInterval;

        try {
            this.autoUpdateCert();
            this.instant = Instant.now();
        } catch (GeneralSecurityException | IOException var5) {
            throw new RuntimeException(var5);
        }
    }

这是执行1之前的方法:

private List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String body) throws GeneralSecurityException, IOException {
        AesUtil decryptor = new AesUtil(apiV3Key);
        ObjectMapper mapper = new ObjectMapper();
        JsonNode dataNode = mapper.readTree(body).get("data");
        List<X509Certificate> newCertList = new ArrayList();
        if (dataNode != null) {
            int i = 0;

            for(int count = dataNode.size(); i < count; ++i) {
                JsonNode encryptCertificateNode = dataNode.get(i).get("encrypt_certificate");
                String cert = decryptor.decryptToString(encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "").getBytes("utf-8"), encryptCertificateNode.get("nonce").toString().replaceAll("\"", "").getBytes("utf-8"), encryptCertificateNode.get("ciphertext").toString().replaceAll("\"", ""));
                CertificateFactory cf = CertificateFactory.getInstance("X509");
                X509Certificate x509Cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(cert.getBytes("utf-8")));

                try {
                    x509Cert.checkValidity();
                } catch (CertificateNotYetValidException | CertificateExpiredException var14) {
                    continue;
                }

                newCertList.add(x509Cert);
            }
        }

        return newCertList;
    }

return语句是一定会执行的,如果有finally 语句,先执行finally 语句,最后执行return;

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632