Skip to content

Commit

Permalink
Fixing NullPointerException with jboss_wildfly integration and user/p…
Browse files Browse the repository at this point in the history
…assword not set (#546)
  • Loading branch information
carlosroman authored Nov 8, 2024
1 parent 7990afe commit 474d2ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========
# 0.49.6 / TBC
* [BUGFIX] Fixed `NullPointerException` on JBoss when user and password not set [#546][]

# 0.49.5 / 2024-10-24
* [FEATURE] Added support for `UnloadedClassCount` metric [#540][]
Expand Down Expand Up @@ -787,6 +788,7 @@ Changelog
[#531]: https://github.com/DataDog/jmxfetch/issues/531
[#534]: https://github.com/DataDog/jmxfetch/issues/534
[#540]: https://github.com/DataDog/jmxfetch/issues/540
[#546]: https://github.com/DataDog/jmxfetch/issues/546
[@alz]: https://github.com/alz
[@aoking]: https://github.com/aoking
[@arrawatia]: https://github.com/arrawatia
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/datadog/jmxfetch/RemoteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public RemoteConnection(Map<String, Object> connectionParams) throws IOException
rmiConnectionTimeout = DEFAULT_RMI_CONNECTION_TIMEOUT;
}

user = (String) connectionParams.get("user");
password = (String) connectionParams.get("password");
if (connectionParams.containsKey("user") && connectionParams.containsKey("password")) {
if (connectionParams.get("user") != null && connectionParams.get("password") != null) {
user = (String) connectionParams.get("user");
password = (String) connectionParams.get("password");
}
}

jmxUrl = (String) connectionParams.get("jmx_url");

if (connectionParams.containsKey("path")) {
Expand Down Expand Up @@ -109,7 +114,13 @@ private Map<String, Object> getEnv(Map<String, Object> connectionParams) {
new JmxfetchRmiClientSocketFactory(rmiTimeout, rmiConnectionTimeout, useSsl);
environment.put("com.sun.jndi.rmi.factory.socket", csf);
environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
environment.put(JMXConnector.CREDENTIALS, new String[] { user, password });

// Don't set `JMXConnector.CREDENTIALS` if `user` or `password` null as this will cause
// a `NullPointerException` when creating a remote connection if null
// https://github.com/DataDog/jmxfetch/issues/545
if (this.user != null && this.password != null) {
environment.put(JMXConnector.CREDENTIALS, new String[] { user, password });
}
return environment;
}

Expand Down

0 comments on commit 474d2ab

Please sign in to comment.