Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing NullPointerException with jboss_wildfly integration and user/password not set #546

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
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
Loading