王木风 2022-01-10 12:14 采纳率: 100%
浏览 58
已结题

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

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

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;
    }
  • 写回答

2条回答 默认 最新

  • 关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月4日
  • 已采纳回答 5月27日
  • 创建了问题 1月10日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。