简体   繁体   English

可能会抛出“NullPointerException”; “activationConfigParser”在这里可以为空

[英]A "NullPointerException" could be thrown; "activationConfigParser" is nullable here

sonar issue声纳问题

1个

private void getGtcj(String gtcjStatusValue, String strArchiveReqd) throws Exception {
    XPathHelper activationConfigParser = null;
    try {
        activationConfigParser = ConfigUtil.getInstance().getConfigParser(new URL((V21Constants.FILE
                + System.getProperty(V21Constants.USER_DIR) + "/vServe21/config/ActivationParameters.xml")));
    } catch (Exception e) {
        log.error(e.getMessage());
    }

    StringBuffer useGTCJSolution = new StringBuffer();
    useGTCJSolution.append(XPathConstants.ACTIVATION_CONFIG_ACTIVATION_PARAM)
            .append("/parameter[@name = '").append(XPathConstants.TAG_NAME_USE_GTCJ_SOLUTION)
            .append("']");

    String useGTCJSolutionStr = activationConfigParser.evaluateXPath(useGTCJSolution.toString());
    log.debug("useGTCJSolutionStr value:" + useGTCJSolutionStr);

    if (useGTCJSolutionStr != null && useGTCJSolutionStr.trim().equalsIgnoreCase(V21Constants.YES)
            && (gtcjStatusValue.equalsIgnoreCase(Statuses.ACTIVATION_SUCCESS)
                    || gtcjStatusValue.equalsIgnoreCase(Statuses.ROLLBACK_SUCCESS)
                    || gtcjStatusValue.equalsIgnoreCase("Rollback Failure"))) {
        log.debug("No need to archive and send response from here.");
    } else {
        log.debug("inside GTCJSolution for GTCJ orders...Archiving and sending response xml");
        if (strArchiveReqd != null && "Yes".equalsIgnoreCase(strArchiveReqd)) {
            archiveXML(responseFileName, V21Constants.VIF_ARCHIVE_RESPONSE_XML_PATH);
        }
        // sending the response XML
        response = new Response();
        response.sendResponseXML(properties, responseXml, bNBSConnectivityFlag, queueName, address);
    }
}

I figured out there should be a finally block after catch, but I don't know what to add inside the finally block.我发现在 catch 之后应该有一个 finally 块,但我不知道在 finally 块中添加什么。 Or is there any other solution?或者还有其他解决方案吗?

When you create the variable activationCOnfigParser you're in a try/Catch block.当您创建变量 activationCOnfigParser 时,您处于 try/Catch 块中。 You can bypass this error:您可以绕过此错误:

private void getGtcj(String gtcjStatusValue, String strArchiveReqd) throws Exception {
XPathHelper activationConfigParser = null;
try {
    activationConfigParser = ConfigUtil.getInstance().getConfigParser(new URL((V21Constants.FILE
            + System.getProperty(V21Constants.USER_DIR) + "/vServe21/config/ActivationParameters.xml")));
} catch (Exception e) {
    actionConfigParser = <DEFAULT VALUE>
    log.error(e.getMessage());

}

In catch block there is that you can replace with a value that actionConfigParser has to assuming in case of exception.在 catch 块中,您可以替换为 actionConfigParser 在出现异常时必须假设的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可能会抛出“NullPointerException”; “上下文”在这里可以为空 - A "NullPointerException" could be thrown; "context" is nullable here SonarQube 可能抛出 NullPointerException; Conn 在这里可以为空 - SonarQube A NullPointerException could be thrown; Conn is nullable here SonarQube Blocker问题NullPointerException可能会因为“联系人”在此处为空而抛出 - SonarQube Blocker Issue NullPointerException might be thrown as 'contacts' is nullable here NullPointerException可能会因为“值”为空而在此处发出声纳警告 - NullPointerException might be thrown as 'value' is nullable here sonar warning 为什么将NullPointerException抛出在这里? - Why the NullPointerException will be thrown here? 我该如何解决squid:S2259`NullPointerException可能会被抛出,因为&#39;getString&#39;在这里可以为空。 - How do I fix squid:S2259 `NullPointerException might be thrown as 'getString' is nullable here`? SonarQube - 可能会抛出“NullPointerException”; - SonarQube - A “NullPointerException” could be thrown; Sonarqube说:可能会抛出“ NullPointerException”。 “ getFolderPath()”可以返回null - Sonarqube says: A “NullPointerException” could be thrown; “getFolderPath()” can return null 可能会抛出“NullPointerException”; “getBody”可以返回 null 声纳 - A “NullPointerException” could be thrown; “getBody” can return null Sonar nullableer = false值上的nullPointerException - nullPointerException on a nullable=false value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM