【发布时间】:2017-08-28 14:47:03
【问题描述】:
我们的扫描在下面的代码中中止,但有以下例外:
org.sonar.java.se.ExplodedGraphWalker$MaximumStepsReachedException: reached limit of 16000 steps for method getServiceProviders#151 in class ServiceProviderService
我们查看了规则 S2259 和 S2583,并希望保留有关空指针的通知。
这在“常规”和调试 (-X) 模式下都会发生,因此不是问题 1406。在我们的例子中,它似乎与 try/catch 相关。 (请参见下面的示例方法。)这可能是问题 1295 的复兴吗? https://jira.sonarsource.com/browse/SONARJAVA-1295 如果是这样,有没有办法简单地将堆栈从 16,000 增加到我们可以继续前进?
示例方法:
public static List<ServiceProvider> getServiceProviders() throws DAOException {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
List<ServiceProvider> serviceProviderList = new ArrayList<>();
try {
con = DatabaseUtils.getConnection();
if (con != null) {
stmt = con.prepareStatement(sqlSelectServiceProviders);
rs = stmt.executeQuery();
while (rs.next()) {
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setId(rs.getLong(1));
serviceProvider.setName(rs.getString(2));
// etc.
serviceProviderList.add(serviceProvider);
}
} else {
DAOException ourDAOException = new DAOException();
ourDAOException.setMessageCode(Consts.ERROR_CANNOT_ESTABLISH_CONNECTIONS);
throw ourDAOException;
}
} catch (DAOException daoexcep) {
throw daoexcep;
} catch (Exception sqlex) {
log.error(ErrorType.SYSTEM + ": " + Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER + " - " + sqlex);
log.error(sqlex);
try {
if (con != null) {
con.rollback();
}
} catch (SQLException ex) {
}
DAOException ourDAOException = new DAOException(sqlex);
ourDAOException.setMessageCode(Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER);
throw ourDAOException;
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
con = null;
}
}
return serviceProviderList;
}
【问题讨论】:
标签: java sonarqube try-catch-finally