When the message is written before sending across the socket/connection, the ObjectOutputStream have no issues but on other side of the connection, it throws the exception after it calls readObject(ObjectInputStream).
I went through the debug process and realized that the 'list' is null even it already got initialized as a class variable. I had to create a temporary List collection before collecting the data from ObjectInputStream then have it assigned to 'list'. That works fine.
I do not understand why the 'list' is null. Is it possible that Reflection, while running OutInputStream, access into the method, readObject(), without any data stored into the memory like 'list'?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Joined: Mar 29, 2011
Wouter Oet wrote:What exception does it throw?
NullPointerException because the class variable, 'list' is null even it already got initialized in that class (private List<Object> list = new LinkedList<Object>();>
cause by: java.lang.NullPointerException
at <package name>.ClassName.readObject(ClassName.java:#)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
After doing some research in my own, I figured it out. Reflection do not need the accessor of the class object, just a string of class' location without knowing the names of the classes, methods etc. at compile time. Now that makes sense that Reflection skips all class variable and all class variables are null no matter if they all already instantiated, implemented or initialized outside the specific method implementation where reflection is accessing into.