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

NullPointerException since 5.19.0 (Add support for Micrometer Observation) #1534

Closed
assopt opened this issue Jan 29, 2025 · 7 comments
Closed
Assignees
Labels
Milestone

Comments

@assopt
Copy link

assopt commented Jan 29, 2025

Describe the bug

java.lang.NullPointerException: Cannot invoke "java.net.InetAddress.getHostAddress()" because the return value of "com.rabbitmq.client.impl.FrameHandler.getAddress()" is null
	at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:445)
	at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1251)
	at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1198)
        ...

The code at line 445 was added in 5.19.0 (Add support for Micrometer Observation).

Other code in the class AMQConnection is null safe. toString() for example uses the method getHostAddress() which explicitly handles the case of the address being null.

Reproduction steps

We know that the address is null because the hostname cannot be resolved. As we have a proxy in between there is no need to resolve the hostname in the first place.

Expected behavior

No NPE even if the hostname cannot be resolved to an address.

Use getHostAddress() instead of this._frameHandler.getAddress().getHostAddress().

Additional context

Including 5.18.0 everything worked. With the update to a newer version as the only change on our side we get the NPE.

@assopt assopt added the bug label Jan 29, 2025
@lukebakken
Copy link
Contributor

Thanks for the report. Since you understand the issue well, a pull request with a fix (and tests) would be appreciated.

@lukebakken lukebakken self-assigned this Jan 29, 2025
@lukebakken lukebakken added this to the 5.25.0 milestone Jan 29, 2025
@michaelklishin
Copy link
Member

As we have a proxy in between there is no need to resolve the hostname in the first place

we will not guess what specifically your environment or client configuration looks like. We do not guess in this community.

Please submit a PR and/or a set of steps to reproduce.

@assopt
Copy link
Author

assopt commented Jan 30, 2025

I will submit a pull request next week.

@acogoluegnes
Copy link
Contributor

@assopt I pushed a fix. Can you tell us more about your environment? I'd be curious to know how the address can be null at this point.

acogoluegnes added a commit that referenced this issue Jan 30, 2025
@assopt
Copy link
Author

assopt commented Jan 31, 2025

In that specific environment we initialize the connection from a server where no hostname resolution is available. So that server uses a socks proxy via its IP address to reach the rabbitmq server via its hostname. The hostname is then resolved by the socks proxy. We cannot use the IP address of the rabbitmq server directly as it may change in the future.
In the code we put the socks proxy in between via delegation.

@acogoluegnes
Copy link
Contributor

OK, thanks for the context. Can you try the latest snapshot to make sure the issue is fixed in your environment?

@assopt
Copy link
Author

assopt commented Feb 3, 2025

Works :-) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants