Sonar爲下面的代碼提供了嚴重違規錯誤(「保留堆棧跟蹤」)。以下方法用於引發異常。我應該採取哪些措施來克服這種違規行爲?如何避免Sonar的「保留堆棧跟蹤」違規?
public void exceptionHandler(String exception) throws PhDashException {
String exceptionMsg = exception.replaceAll("-", "_");
ExceptionPhDash pHDashExceptionMapper = new ExceptionPhDash();
try {
pHDashExceptionMapper = new ObjectMapper().readValue(exceptionMsg, ExceptionPhDash.class);
} catch (JsonParseException e) {
LOGGER.info(e.getMessage());
} catch (JsonMappingException e) {
LOGGER.info(e.getMessage());
} catch (IOException e) {
LOGGER.info(e.getMessage());
}
throw new PhDashException(pHDashExceptionMapper.getMessage());
}
嘗試將整個異常傳遞給記錄器而不是其消息。 –
@Niks Tyagi - 但最好的做法是避免printStackTrace()?對嗎? http://gazelle.ihe.net/sonar/rules/show/pmd:AvoidPrintStackTrace?layout=false –
是更新爲LOGGER.info(例外) – Kick