Somehow I get a null pointer exception here with JDK 1.6.0_14:
HttpSession session = request.getSession(true);
LinkedList<MyObject> list = (LinkedList<MyObject>) session.getAttribute(MY_LIST_KEY);
....
list.addFirst( new MyObject(str1, str2, map) );
Then I get the following:
at java.util.LinkedList.addBefore(LinkedList.java:779)
Here's the method:
private Entry<E> addBefore(E e, Entry<E> entry) {
Entry<E> newEntry = new Entry<E>(e, entry, entry.previous);
newEntry.previous.next = newEntry;
newEntry.next.previous = newEntry;
size++;
modCount++;
return newEntry;
}
which is called
public void addFirst(E e) {
addBefore(e, header.next);
}
Is there any weird way that the list can be serialized / deserialized to split the title to make this happen? I do not see how this can be unsuccessful.
Here are serialization methods for LinkedList
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
s.defaultWriteObject();
s.writeInt(size);
for (Entry e = header.next; e != header; e = e.next)
s.writeObject(e.element);
}
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
int size = s.readInt();
header = new Entry<E>(null, null, null);
header.next = header.previous = header;
for (int i=0; i<size; i++)
addBefore((E)s.readObject(), header);
}
source
share