Skip to content

Conversation

myProjectsRavi
Copy link

This PR implements support for Spring Cloud's InetUtils in DefaultApplicationFactory.getLocalHost().

  • Injects Optional into DefaultApplicationFactory
  • Resolves preferred non-loopback address if configured via spring.cloud.inetutils.*
  • Falls back to InetAddress.getLocalHost() if InetUtils is absent or fails
  • Adds conditional bean definition for Optional in auto-configuration

Closes #1323.

@myProjectsRavi myProjectsRavi requested a review from a team as a code owner August 27, 2025 08:52
Copy link
Member

@erikpetzold erikpetzold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not yet have a look at the changes in detail yet, but please clean up the PR

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all these oauth2 sample files do not belong here

*/
public class DefaultApplicationFactory implements ApplicationFactory {

// Removed InetUtils dependency; using standard Java APIs for host resolution.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was no InetUtils dependency removed here, please remove the comment

return address.getHostName();
default:
return address.getCanonicalHostName();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change the syntax here?


private final MetadataContributor metadataContributor;

private final Optional<?> inetUtils;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not one of the contributors of this project but just a client of it, but I must say that this <?> really smells of bad code and potential broken injection points...

try {
java.lang.reflect.Method m = utils.getClass().getMethod("findFirstNonLoopbackHostInfo");
Object host = m.invoke(utils);
if (host instanceof String && StringUtils.hasText((String) host)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can probably be simplified with pattern matching for instanceof if the Java version of the project allows it ;)

if (this.inetUtils != null && this.inetUtils.isPresent()) {
Object utils = this.inetUtils.get();
try {
java.lang.reflect.Method m = utils.getClass().getMethod("findFirstNonLoopbackHostInfo");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may easily break in case of native compilation.

@erikpetzold your thoughts?

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

Successfully merging this pull request may close these issues.

Support of spring InetUtils in DefaultApplicationFactory
3 participants