【发布时间】:2023-01-30 04:48:21
【问题描述】:
声纳问题
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);
}
}
我发现在 catch 之后应该有一个 finally 块,但我不知道在 finally 块中添加什么。或者还有其他解决方案吗?
【问题讨论】:
-
您能否添加收到警告/错误的行?
-
得到一个“NullPointerException”可能会被抛出; “activationConfigParser”在这里可以为空。
-
试想如果
try块中的代码抛出异常会发生什么:异常将被catch (Exception e) { log.error(e.getMessage()); }块捕获,但此时activationConfigParser仍然是null,然后activationConfigParser.evaluateXPath(...)抛出NullPointerException。 -
你为什么在那里捕获那个异常?当
try块内的代码实际抛出此异常时,您期望整个方法有什么行为?
标签: java nullpointerexception sonarqube