Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/metricshub/snmp/client/ISnmpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ default String stripDot(String s) {
* @throws Exception on error (e.g. no such OID).
*/
String walk(String oid) throws Exception;

/**
* Frees any resources held by the client, such as network connections or file handles or memory space.
*/
void freeResources();
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,9 @@ public String walk(String oid) {

return walkResult.toString();
}

@Override
public void freeResources() {
oidValues.clear();
}
}
1 change: 1 addition & 0 deletions src/main/java/org/metricshub/snmp/client/SnmpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
this.host = host;
this.port = port;
this.snmpVersion = version;
this.retryIntervals = retryIntervals;

Check warning on line 129 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

EI_EXPOSE_REP2

new org.metricshub.snmp.client.SnmpClient(String, int, int, int[], String, String, String, String, String, String, String, byte[]) may expose internal representation by storing an externally mutable object into SnmpClient.retryIntervals
Raw output
 This code stores a reference to an externally mutable object into the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.
this.community = community;
this.authType = authType;
this.authUsername = authUsername;
Expand All @@ -134,7 +134,7 @@
this.privacyType = privacyType;
this.privacyPassword = privacyPassword;
this.contextName = contextName;
this.contextEngineID = contextID;

Check warning on line 137 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

EI_EXPOSE_REP2

new org.metricshub.snmp.client.SnmpClient(String, int, int, int[], String, String, String, String, String, String, String, byte[]) may expose internal representation by storing an externally mutable object into SnmpClient.contextEngineID
Raw output
 This code stores a reference to an externally mutable object into the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.

// Properly create the SNMP context, based on these properties
initialize();
Expand All @@ -153,27 +153,27 @@
// In case of SNMP v3, check the authType and privType (if not empty)
if (version == SNMP_V3) {
if (authType != null) {
if (!authType.isEmpty()) {
if (! SNMP_AUTH_PROTOCOLS.contains(authType)) {
throw new IllegalArgumentException("Invalid authentication method '" + authType + "'." +
" (Valid options are: '" + SNMP_AUTH_MD5
+ "', '" + SNMP_AUTH_SHA
+ "', '" + SNMP_AUTH_SHA256
+ "', '" + SNMP_AUTH_SHA512
+ "', '" + SNMP_AUTH_SHA224
+ "', '" + SNMP_AUTH_SHA384
+ "', or empty)");
}

Check warning on line 166 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / PMD

Design CollapsibleIfStatements

This if statement could be combined with its parent
}

Check warning on line 167 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / PMD

Design CollapsibleIfStatements

This if statement could be combined with its parent
}

if (privacyType != null) {
if (!privacyType.isEmpty()) {
if (! SNMP_PRIVACY_PROTOCOLS.contains(privacyType)) {
throw new IllegalArgumentException(
"Invalid privacy method '" + privacyType + "'." + " (Valid options are:'" + SNMP_PRIVACY_DES
+ "', '" + SNMP_PRIVACY_AES + "', '" + SNMP_PRIVACY_AES192 + "', '" + SNMP_PRIVACY_AES256 + "', or empty)");
}

Check warning on line 176 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / PMD

Design CollapsibleIfStatements

This if statement could be combined with its parent
}

Check warning on line 177 in src/main/java/org/metricshub/snmp/client/SnmpClient.java

View workflow job for this annotation

GitHub Actions / PMD

Design CollapsibleIfStatements

This if statement could be combined with its parent
}
}
Expand Down Expand Up @@ -305,6 +305,7 @@
* Releases the resources associated to this instance
* (or so at least we believe...)
*/
@Override
public void freeResources() {
if (contextv1 != null) {
contextv1.destroy();
Expand Down
Loading