When an Inet6Address object is deserialized the scope_id can be left incorrect when the scoped interface in the serialized object does not exist on the deserializing host.
This relates to the readObject method's use
of NetworkInterface.getByName, and how it processes this interface to obtain
the scope id. In the code extract below the inner try catch block which
is searching for the scope id can throw an UnknownHostException which is
silently caught, and the scope id will remain as per its serialised value.
It would seem appropriate to set the scope_id to 0 ,
and correspondingly scope_id_set = 0.
try {
scope_ifname = NetworkInterface.getByName(ifname);
if (scope_ifname != null) {
scope_ifname_set = true;
try {
scope_id = deriveNumericScope(scope_ifname);
} catch (UnknownHostException e) {
// typically should not happen, but it may be that
// the machine being used for deserialization has
// the same interface name but without IPv6 configured.
}
} else {
/* the interface does not exist on this system, so we clear
* the scope information completely */
scope_id_set = false;
scope_ifname_set = false;
scope_id = 0;
}
} catch (SocketException e) {}
The logic here is that if an interface name has been set in the serialized object,
look for a corresponding NetworkInterface on the deserializing host, then look for its
scope id. The scope id serach can throw an UnknownHostException, typically with a no scope id found.
This then leaves
the value of scope id as per its serialized value. While scope_id = 0 and
scope_id_set = false would appear more appropriate in this failed scope id search context
In reality, the only state of an Inet6Address,
which will be consistent across serialization/deserialization
and across hosts, is the hostName and the address.
The scope_id is effectively transient outside of
the host on which the Inet6Address was serialized.
This relates to the readObject method's use
of NetworkInterface.getByName, and how it processes this interface to obtain
the scope id. In the code extract below the inner try catch block which
is searching for the scope id can throw an UnknownHostException which is
silently caught, and the scope id will remain as per its serialised value.
It would seem appropriate to set the scope_id to 0 ,
and correspondingly scope_id_set = 0.
try {
scope_ifname = NetworkInterface.getByName(ifname);
if (scope_ifname != null) {
scope_ifname_set = true;
try {
scope_id = deriveNumericScope(scope_ifname);
} catch (UnknownHostException e) {
// typically should not happen, but it may be that
// the machine being used for deserialization has
// the same interface name but without IPv6 configured.
}
} else {
/* the interface does not exist on this system, so we clear
* the scope information completely */
scope_id_set = false;
scope_ifname_set = false;
scope_id = 0;
}
} catch (SocketException e) {}
The logic here is that if an interface name has been set in the serialized object,
look for a corresponding NetworkInterface on the deserializing host, then look for its
scope id. The scope id serach can throw an UnknownHostException, typically with a no scope id found.
This then leaves
the value of scope id as per its serialized value. While scope_id = 0 and
scope_id_set = false would appear more appropriate in this failed scope id search context
In reality, the only state of an Inet6Address,
which will be consistent across serialization/deserialization
and across hosts, is the hostName and the address.
The scope_id is effectively transient outside of
the host on which the Inet6Address was serialized.
- duplicates
-
JDK-8007373 Inet6Address serialization incompatibility
- Closed
- relates to
-
JDK-8007373 Inet6Address serialization incompatibility
- Closed
-
JDK-8004675 Inet6Address.getHostAddress should use string scope identifier where available
- Closed