FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux xxx.xxx.xxx.xxx 2.6.20-1.2948.fc6 #1 SMP Fri Apr 27 18:53:15 EDT 2007 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When reading in an Inet6Address that has previously been serialized, there are cases where a NullPointerException is thrown.
If a link local IPv6 address is created on a machine "A" with a scope ID of a network adapter which does not exist on a machine "B", and the object is sent over the wire from A to B, a NPE is raised when the object is being reconstructed on B.
Similarly, if a link local IPv6 address is created on a machine with a scope ID of a network adapter that is enabled or disabled (ex: eth1.5), and is serialized to disk, if the adapter is brought down, and the address is attempted to be reconstructed, the exception will be raised. (it is this case that I have provided a test case for)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I created a VLAN adapter on my machine which can be enabled or disabled via the typical 'ifup' and 'ifdown' commands. (In my case, it was 'eth1.5').
With the adapter up, I ran the 'WriteIPv6' program (documented below). A 'test.ser' file is written, containing a serialized Inet6Address (which is a link local IPv6 address with a scope ID corresponding to the adapter which is enabled or disabled 'eth1.5')
I disabled the adapter. (It no longer shows up in 'ifconfig' output)
I then ran the 'ReadIPv6' program (documented below).
The exception was raised.
This failed in JDK 1.6 as well as 1.5.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the address to be reconstructed, but without a scope ID.
The Inet6Address.readObject() method contains the following block:
try {
scope_ifname = NetworkInterface.getByName(ifname);
try {
scope_id = deriveNumericScope (scope_ifname);
} catch (UnknownHostException e) {
// should not happen
assert false;
}
} catch (SocketException e) {}
if (scope_ifname == null) {
/* 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;
}
However, the contract for NetworkInterface.getByName(String) says it will return "A NetworkInterface with the specified name, or null if there is no network interface with the specified name."
If the 'scope_ifname' variable is returned as null, the subsequent call to 'deriveNumericScope (NetworkInterface)' will throw an exception, as the null is dereferenced.
I would expect similar results as if a SocketException was raised during the block above: the if block for '(scope_ifname == null)' would be entered, and the scope id information would be indicated as not being set.
ACTUAL -
A NullPointerException is raised during the readObject() processing for the Inet6Address. (specifically, it is in the deriveNumericScope() routine)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at java.net.Inet6Address.deriveNumericScope(Inet6Address.java:343)
at java.net.Inet6Address.readObject(Inet6Address.java:406)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at ReadIPv6.main(ReadIPv6.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Two files. The first will write out an Inet6Address to a file:
import java.io.*;
import java.net.*;
import java.util.*;
public class WriteIPv6 {
public static void main(String[] args) {
try {
InetAddress iaddr = InetAddress.getByName("fe80::202:6cff:fe82:ac30%eth1.5");
System.out.println(iaddr);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("test.ser")));
oos.writeObject(iaddr);
oos.close();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
------
The second will read in the previously written file:
import java.io.*;
import java.net.*;
import java.util.*;
public class ReadIPv6 {
public static void main(String[] args) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("test.ser")));
InetAddress iaddr2 = (InetAddress)ois.readObject();
ois.close();
System.out.println(iaddr2);
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
------
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I believe the Inet6Addresses need to have their scope information erased (so, I need to create new IPv6 objects with no scope ids) before serializing them between machines or to disk.
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux xxx.xxx.xxx.xxx 2.6.20-1.2948.fc6 #1 SMP Fri Apr 27 18:53:15 EDT 2007 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When reading in an Inet6Address that has previously been serialized, there are cases where a NullPointerException is thrown.
If a link local IPv6 address is created on a machine "A" with a scope ID of a network adapter which does not exist on a machine "B", and the object is sent over the wire from A to B, a NPE is raised when the object is being reconstructed on B.
Similarly, if a link local IPv6 address is created on a machine with a scope ID of a network adapter that is enabled or disabled (ex: eth1.5), and is serialized to disk, if the adapter is brought down, and the address is attempted to be reconstructed, the exception will be raised. (it is this case that I have provided a test case for)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I created a VLAN adapter on my machine which can be enabled or disabled via the typical 'ifup' and 'ifdown' commands. (In my case, it was 'eth1.5').
With the adapter up, I ran the 'WriteIPv6' program (documented below). A 'test.ser' file is written, containing a serialized Inet6Address (which is a link local IPv6 address with a scope ID corresponding to the adapter which is enabled or disabled 'eth1.5')
I disabled the adapter. (It no longer shows up in 'ifconfig' output)
I then ran the 'ReadIPv6' program (documented below).
The exception was raised.
This failed in JDK 1.6 as well as 1.5.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the address to be reconstructed, but without a scope ID.
The Inet6Address.readObject() method contains the following block:
try {
scope_ifname = NetworkInterface.getByName(ifname);
try {
scope_id = deriveNumericScope (scope_ifname);
} catch (UnknownHostException e) {
// should not happen
assert false;
}
} catch (SocketException e) {}
if (scope_ifname == null) {
/* 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;
}
However, the contract for NetworkInterface.getByName(String) says it will return "A NetworkInterface with the specified name, or null if there is no network interface with the specified name."
If the 'scope_ifname' variable is returned as null, the subsequent call to 'deriveNumericScope (NetworkInterface)' will throw an exception, as the null is dereferenced.
I would expect similar results as if a SocketException was raised during the block above: the if block for '(scope_ifname == null)' would be entered, and the scope id information would be indicated as not being set.
ACTUAL -
A NullPointerException is raised during the readObject() processing for the Inet6Address. (specifically, it is in the deriveNumericScope() routine)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at java.net.Inet6Address.deriveNumericScope(Inet6Address.java:343)
at java.net.Inet6Address.readObject(Inet6Address.java:406)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at ReadIPv6.main(ReadIPv6.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Two files. The first will write out an Inet6Address to a file:
import java.io.*;
import java.net.*;
import java.util.*;
public class WriteIPv6 {
public static void main(String[] args) {
try {
InetAddress iaddr = InetAddress.getByName("fe80::202:6cff:fe82:ac30%eth1.5");
System.out.println(iaddr);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("test.ser")));
oos.writeObject(iaddr);
oos.close();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
------
The second will read in the previously written file:
import java.io.*;
import java.net.*;
import java.util.*;
public class ReadIPv6 {
public static void main(String[] args) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("test.ser")));
InetAddress iaddr2 = (InetAddress)ois.readObject();
ois.close();
System.out.println(iaddr2);
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
------
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I believe the Inet6Addresses need to have their scope information erased (so, I need to create new IPv6 objects with no scope ids) before serializing them between machines or to disk.
- duplicates
-
JDK-6656849 NullPointerException thrown while de-serializing IPV6 Address.
-
- Closed
-