Drag and Drop causes StackOverflow

Hi everybody,

Within my graph I am using a subclass of a JGoText component. When I try to drag and drop the JGoText object to a second view then I receive a StackOverflow exception.
This happens by the following line: Object data = tr.getTransferData(jgoflavor); in the doDrop() method of the JGoView where I dropped the JGoText object.

Can anybody help?

Many thanks in advance,
Marco


Stack Trace:
java.lang.StackOverflowError
at java.io.ObjectInputStream$BlockDataInputStream.readByte(Obje ctInputStream.java:2668)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1689)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at


java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)



Hi everybody,

I forgot to say that we are using JGo 4.13

Many thanks for help,
Marco

Are your classes properly serializable?
Perhaps some fields need to be declared transient. (Remember that your code then needs to be able to deal with null values for such fields.)

Hi Walter,

Many thanks for your fast response. I have declared some fields in the
classes as transient. But how could I find the class which causes the
problems or the field which should be transient.

Any help would be fantastic…

Many thanks for your time,
Marco

Hi Walter,

I am not sure if this is of any help, but I am using a JGoView with a
modified version of the RecordNode class from the JGo examples.

Many thanks for your time,
Marco

Hi Walter,

sorry for sending various responses.

The above error only occurs if the RecordNode contains a lot of attributes.

Thanks for your help
Marco

If your IDE/debugger hasn’t been of any help, I would try serializing and deserializing a JGoDocument containing an instance of your RecordNode. Use ObjectOutputStream and ObjectInputStream. See if you get any exceptions that have any meaningful information.

Hi Walter

I have serialized the JGoDocument and when I try to read it than I get the stack trace below:

I have used the following code for this:

     &nbs p;       try

     &nbs p;       {

     &nbs p;          

FileOutputStream file = new FileOutputStream(new File(“c:/test.out”));

     &nbs p;          

ObjectOutputStream stream = new ObjectOutputStream(file);

     &nbs p;          

stream.writeObject(this.getDocument());

     &nbs p;          

stream.close();

     &nbs p;          

file.close();

     &nbs p;           

     &nbs p;          

FileInputStream inputFile = new FileInputStream(new
File(“c:/test.out”));

     &nbs p;          

ObjectInputStream iStream = new ObjectInputStream(inputFile);

     &nbs p;          

Object o = iStream.readObject();

     &nbs p;       } catch (Exception ex)

     &nbs p;       {

     &nbs p;          

ex.printStackTrace();

     &nbs p;       }

Stack Trace:
java.lang.StackOverflowError
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Obje ctInputStream.java:2500)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1449)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1693)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at
… java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStrea m.java:1912)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.j ava:1836)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1713)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1299)

I don’t know what the problem might be. What change did you make recently to cause this to happen? Somehow you need to narrow down the circumstances under which the stack overflow occurs.

Hi Walter,

In my view I use a subclass of the RecordNode class from the examples.

It works perfectly if the view only contains one RecordNode subclass
but as soon as a second RecordNode object - with a lot of JGoText
objects - is added to the JGoView, the error happens.

Thanks for your time,
Marco

Hi Walter,

I have added the following code to my RecordNode, RecordNodeAttribute (simple subclass of JGoText) and JGoDocument:

private void writeObject(java.io.ObjectOutputStream out)
    throws IOException
    {
    System.out.println("recordnode write");
    
    out.defaultWriteObject();
    }

private void readObject(java.io.ObjectInputStream in)
    throws IOException, ClassNotFoundException
    {
    System.out.println("recordnode read");
    in.defaultReadObject();
    }

Now the terminal output says that writing of the classes was
successful. Reading of the JGoDocument the first RecordNode and its
RecordNodeAttributes was also successful. Then the error seems to
happen by reading the second RecordNode. Because the terminal output
says “recordnode read” and then it is followed by stack trace.

So I think the problem is in serializing the RecordNodes .
Since I only allow copy and pasting of the RecordNodeAttribute objects,
is it possible not to serialize the RecordNodeAttributes?

Thanks for your time,
Marco

Hmmm, I’m able to serialize and deserialize a whole bunch of Record Nodes, with many items and at different scrolling positions.
If I get a chance I’ll investigate further.

Hi Walter,

I found the problem! The exception also happens when serializing the current JGoSelection with ObjectOutputStream and ObjectInputStream.

I have patched the JDK and found out that during serialization the
JGoArea serializes the JGoObjList field which contained in my test case
around 400 items. An exception is then thrown during its serialization.

My workaround is overriding dragGestureRecognized method of the
JGoView. Within the overriden method I created a new instance of
JGoView where I added a copy of the selected objects to it. Now the
JGoArea object from the RecordNode class was not included in the newly
created JGoView.

Do you know any better solution to solve this?

I also noticed that I can reproduce the excetion with the JGo
examples. I have slightly modified the Demo1 example so that the
RecordNode contains 300 entries.
The exception happens when you add the RecordNode -with 300 entries- to
the view, then select the RecordNode object, and afterwards press
Ctrl-c for copying it to the clipboard.

Thanks a lot for your time and fast responses,
Marco

Hi Walter,

could you reproduce this in the Demo1 example? Do you have any better solution how to solve this?

Many thanks in advance,
Marco

OK, I made the same change you suggest, to increase the number of RecordNode items to 300, and I was (finally) able to reproduce the problem you see.
Since the exception has to do with exceeding the stack, I tried running java with the -Xss option at various values. I found that a value of 1 million worked fine:
java -Xss1m com.nwoods.jgo.examples.demo1.Demo1
I tried increasing the number of items to 5000 (that takes a few seconds to create), and found that copying to the clipboard required -Xss5m.
I don’t know why Sun’s serialization is implemented the way it is. It appears that the problem has nothing to do with JGo, but with how long lists are serialized.