0

In below inner class of java.net.InetAddress, there is a native method - isIPv6Supported(). Suppose, I am using Springs as application framework and deploying my application in Weblogic server, question is that whether this native method will be implemented by Weblogic, Springs or both.

My guess is that it should be implemented by both, but when I try to search Spring source code then this method is not found anywhere but ideally it should be there otherwise how a HTTP connection will happen, this is called before lookupAllHostAddr() and lookup for the DNS has to happen before a HTTP connection is established.

class InetAddressImplFactory {

    static InetAddressImpl create() {
    Object o;
    if (isIPv6Supported()) {
        o = InetAddress.loadImpl("Inet6AddressImpl");
    } else {
        o = InetAddress.loadImpl("Inet4AddressImpl");
    }
    return (InetAddressImpl)o;
    }

    static native boolean isIPv6Supported();
}
pjj
  • 2,015
  • 1
  • 17
  • 42
  • 1
    Probably none of the above. It'll be implemented by the JRE in **native code**. – Elliott Frisch Aug 02 '16 at 02:42
  • @ElliottFrisch I don't think so because I have 2 applications deployed in same JVM, now once of them is using `Inet6AddressImpl` while other one is using `Inet4AddressImpl`, I haven't set any Java argument to prefer either IPv6 or IPv4, so my guess is going that in one case it is picking up Spring's implementation and in other case Weblogic implementation .. – pjj Aug 02 '16 at 02:46
  • @ElliottFrisch There is lot of native code in `java.sql` and it is implemented by JDBC drivers, similar way I think it would depend upon the runtime or application framework ... – pjj Aug 02 '16 at 02:49
  • `InetAddress` is a JRE class, `native` methods are implemented by the JRE implementation of the given OS. It isn't implemented by another container as it is part of the JRE. It would even be used if you didn't use Spring but just a simple class with only a main method and would run that from the command line. See http://stackoverflow.com/questions/6101311/what-is-the-native-keyword-in-java-for – M. Deinum Aug 02 '16 at 06:52
  • @M.Deinum: But isn't classes from `java.sql` part of JRE, and there are many native methods in it, don't remember but I guess `getConnection` is a native method, and all the native methods from `java.sql` are implemented by different JDBC drivers .. If it is really the case that always the JRE implementor will have it then why I am experiencing different behaviour in 2 different applications, and both are running on same JRE .. Can you confirm me this - suppose I am making a HTTP request, then definitely `InetAddress` class will come into picture, got getting the IP from domain name, right? – pjj Aug 03 '16 at 01:35
  • you are confusing `abstract` and `native`. There are no native calls in the sql packages. Only interfaces which are implemented by providers, but that is a whole different thing than `native`. – M. Deinum Aug 04 '16 at 08:26
  • see https://www.codesearch.cloud/openjdk/xref/jdk10u/src/java.base/unix/native/libnet/InetAddressImplFactory.c?r=47216%3A71c04702a3d5 it's implemented by JRE. – fishautumn Sep 19 '19 at 07:39

0 Answers0