You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
coverity 1116509: heavy entanglement of prepared statements and result sets hope I got the logic right. this is for very old versions, might be worth phasing out unless someone still uses it.
@@ -137,36 +127,30 @@ public String getCurrentVersion() {
137
127
}
138
128
139
129
// Use nics table information and is_static_nat field from firewall_rules table to determine version information
140
-
try {
141
-
s_logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2");
142
-
pstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'");
143
-
rs = pstmt.executeQuery();
130
+
s_logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2");
131
+
try (PreparedStatementpstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'");
132
+
ResultSetrs = pstmt.executeQuery();){
144
133
if (!rs.next()) {
145
134
thrownewCloudRuntimeException("Unable to determine the current version, version table exists and empty, nics table doesn't exist");
146
135
} else {
147
-
pstmt = conn.prepareStatement("SELECT is_static_nat from firewall_rules");
148
-
pstmt.executeQuery();
149
-
thrownewCloudRuntimeException("Unable to determine the current version, version table exists and empty, " +
150
-
"nics table doesn't exist, is_static_nat field exists in firewall_rules table");
136
+
try (PreparedStatementpstmt_static_nat = conn.prepareStatement("SELECT is_static_nat from firewall_rules"); ) {
137
+
pstmt_static_nat.executeQuery();
138
+
thrownewCloudRuntimeException("Unable to determine the current version, version table exists and empty, " +
139
+
"nics table doesn't exist, is_static_nat field exists in firewall_rules table");
140
+
} catch (finalSQLExceptione) {
141
+
s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2");
142
+
return"2.2.2";
143
+
}
151
144
}
152
145
} catch (finalSQLExceptione) {
153
-
s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2");
154
-
return"2.2.2";
155
-
} finally {
156
-
rs.close();
157
-
pstmt.close();
146
+
thrownewCloudRuntimeException("Unable to determine the current version, version table exists and empty, query for nics table yields SQL exception", e);
158
147
}
159
148
} else {
160
149
returnupgradedVersions.get(0);
161
150
}
162
151
163
152
} catch (finalSQLExceptione) {
164
153
thrownewCloudRuntimeException("Unable to get the current version", e);
0 commit comments