JDK-7115956 : InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-11-27
  • Updated: 2022-11-30
  • Resolved: 2022-11-30
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
IP: 192.168.0.103 Subnetmask: 255.255.255.000

A DESCRIPTION OF THE PROBLEM :
I'm trying to get a subnet prefix with InterfaceAddress.getNetworkPrefixLength() but it always returns 128 (except 127.0.0.1 this returns 8).

It is exactly the same bug like this one:  http://bugs.sun.com/view_bug.do?bug_id=6707289

The above bug is marked is fixed but I don't think that it is fixed!



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String[] args) throws Exception {
        Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
        while (ifaces.hasMoreElements()) {
            NetworkInterface iface = ifaces.nextElement();
            for (InterfaceAddress ifaceAddress : iface.getInterfaceAddresses()) {
                System.out.println("iface " + iface.getName() +
                                   " has address " + ifaceAddress.getAddress() +
                                   "/" + ifaceAddress.getNetworkPrefixLength());
            }
        }
    }
---------- END SOURCE ----------

Comments
Could not reproduce this. Tried on Windows 11, JDK 11,17,20, both with and without -Djava.net.preferIPv4Stack=true. Results: iface lo has address /127.0.0.1/8 iface lo has address /0:0:0:0:0:0:0:1/128 iface eth5 has address /192.168.100.46/24 iface eth5 has address /fe80:0:0:0:d2d3:31d5:e50f:2b70%eth5/128
30-11-2022