Why an object doesn't change when I send it through writeObject method?
<p>I'm making networking program with Java. As the title, the object which server is trying to send is changed in client which receives it. I'm trying to change the object which exists in client before I receive the new one from server.
Here's my codes. First one is Server.sendIdea and second is Client.rcvIdea.</p>

<pre><code>void sendIdea(Idea _idea) throws IOException {
    objectOS.flush();
    Idea idea = _idea;
//when I look into 'idea' it's fine
    objectOS.writeObject(idea);
}
</code></pre>

<p>..</p>

<pre><code>Idea rcvIdea(int _ideaCode) throws ClassNotFoundException, IOException {
    objectOS.writeObject("sendIdea");
    objectOS.writeObject(_ideaCode);
    Idea returnValue = (Idea) objectIS.readObject();
//when I look into 'returnValue', it is not the one 'sendIdea' has sent.
    return returnValue;
}
</code></pre>

<p>As you can see, <code>sendIdea(Idea _idea)</code> is sending an object from the class <code>Idea</code> by using <code>writeObject</code> method. And <code>rcvIdea()</code> is receiving the object by using <code>readObject()</code> method. (I'm sure you don't have to know about class <code>Idea</code> in detail). The client actually received some <code>Idea</code>s at start of this program by this method and there was no problem. But when I try to receive the same but slightly changed object <code>Idea</code> by this method, in <code>Client</code> class the object does not change, not like in <code>Server</code> class where the object which is going to be sent by <code>sendIdea</code> method is changed correctly. I tried about 5 hours to solve this problem. I checked all the codes line by line and found nothing. I'm pretty sure that writeObject or readObject method have problem. I tried <code>objectOS.flush()</code> to make clear of the stream and many other trials. I hope that I can find the problem. Below is some codes in my program</p>

<p>Client.class
    package ideaOcean;</p>

<pre><code>import java.awt.HeadlessException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import data.Idea;
import data.Opinion;
import data.Profile;

public class Client {
Socket socket;
OutputStream os;
ObjectOutputStream objectOS;
InputStream is;
ObjectInputStream objectIS;
MainWindow mainWindow;

int idCode;
String email, password;
Profile myProfile;
ArrayList&lt;Idea&gt; myIdeas;
ArrayList&lt;Opinion&gt; myOpinions;
ArrayList&lt;Integer&gt; newIdeasCodes, hotIdeasCodes;
ArrayList&lt;Idea&gt; newIdeas, hotIdeas;

String command;

static final String SERVER_IP = "127.0.0.1";// 
static final int SERVER_PORT_NUM = 5000;

public static void main(String[] args) {
    Client client = new Client();
    client.mainWindow = new MainWindow();

    client.mainWindow.setVisible(true);

    client.mainWindow.showLoginPg();
    try {
        while (!client.loginCheck()) {// login
            continue;
        }
    } catch (HeadlessException | NumberFormatException | ClassNotFoundException | IOException e) {
        e.printStackTrace();
    }
    System.out.println("[login complete]");

    try {
        client.myProfile = client.rcvProfile(client.idCode);// get myProfile
        int i;
        for (i = 0; i &lt; client.myProfile.myIdeaCode.size(); i++) {
            client.myIdeas.add(client.rcvIdea(client.myProfile.myIdeaCode.get(i)));
        }
        for (i = 0; i &lt; client.myProfile.myOpinionCode.size(); i++) {
            client.myOpinions.add(client.rcvOpinion(client.myProfile.myOpinionCode.get(i)));
        }
        // ***************************
    } catch (ClassNotFoundException | IOException e1) {
        e1.printStackTrace();
    }

    try {
        client.rcvNewIdeas(12);
        client.mainWindow.newOcean.floatingIdeas = client.newIdeas;
        client.mainWindow.newOcean.arrangeFloatingPanels();

        client.rcvHotIdeas(12);
        client.mainWindow.hotOcean.floatingIdeas = client.hotIdeas;
        client.mainWindow.hotOcean.arrangeFloatingPanels();
    } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
    }

    client.mainWindow.setMyPg(client.myProfile, client.myIdeas, client.myOpinions);
    client.mainWindow.showMainPg();

    client.start();
}

public Client() {
    try {
        socket = new Socket(SERVER_IP, SERVER_PORT_NUM);

        System.out.println("Connected to Server!");

        os = socket.getOutputStream();
        objectOS = new ObjectOutputStream(os);
        is = socket.getInputStream();
        objectIS = new ObjectInputStream(is);

        myIdeas = new ArrayList&lt;&gt;();
        myOpinions = new ArrayList&lt;&gt;();
        newIdeasCodes = new ArrayList&lt;&gt;();
        hotIdeasCodes = new ArrayList&lt;&gt;();
        newIdeas = new ArrayList&lt;&gt;();
        hotIdeas = new ArrayList&lt;&gt;();

    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

void start() {
    while (true) {
        try {
            if (mainWindow.newBtnClicked) {
                rcvNewIdeas(12);
                mainWindow.newOcean.floatingIdeas = newIdeas;
                mainWindow.newOcean.arrangeFloatingPanels();
                mainWindow.newBtnClicked = false;
            } else if (mainWindow.hotBtnClicked) {
                rcvHotIdeas(12);
                mainWindow.hotOcean.floatingIdeas = hotIdeas;
                mainWindow.hotOcean.arrangeFloatingPanels();
                mainWindow.hotBtnClicked = false;
            } else if (mainWindow.newOcean.detailBtnClicked) {

                updateIdeaDetailFrame(mainWindow.newOcean.clickedIdea);
                mainWindow.newOcean.detailBtnClicked = false;

            } else if (mainWindow.hotOcean.detailBtnClicked) {

                updateIdeaDetailFrame(mainWindow.hotOcean.clickedIdea);
                mainWindow.hotOcean.detailBtnClicked = false;

            } else if (mainWindow.ideaDetailFrame.saveOpinionBtnClicked) {

                sendOpinion(mainWindow.ideaDetailFrame.newOpinion);
                updateIdeaDetailMainPanel(rcvIdea(mainWindow.ideaDetailFrame.idea.ideaCode));
                mainWindow.ideaDetailFrame.saveOpinionBtnClicked = false;

            } else if (mainWindow.writeIdeaPg.postIdeaBtnClicked) {

                sendIdea(mainWindow.writeIdeaPg.thisIdea);
                mainWindow.writeIdeaPg.postIdeaBtnClicked = false;

            } else if (mainWindow.newOcean.plusBtnClicked) {

                objectOS.writeObject("plusBtnClicked");
                objectOS.writeObject(mainWindow.newOcean.plusMinusClickedIdeaCode);
                mainWindow.newOcean.plusBtnClicked = false;

            } else if (mainWindow.newOcean.minusBtnClicked) {

                objectOS.writeObject("minusBtnClicked");
                objectOS.writeObject(mainWindow.newOcean.plusMinusClickedIdeaCode);
                mainWindow.newOcean.minusBtnClicked = false;

            } else if (mainWindow.hotOcean.plusBtnClicked) {

                objectOS.writeObject("plusBtnClicked");
                objectOS.writeObject(mainWindow.hotOcean.plusMinusClickedIdeaCode);
                mainWindow.hotOcean.plusBtnClicked = false;

            } else if (mainWindow.hotOcean.minusBtnClicked) {

                objectOS.writeObject("minusBtnClicked");
                objectOS.writeObject(mainWindow.hotOcean.plusMinusClickedIdeaCode);
                mainWindow.hotOcean.minusBtnClicked = false;

            } else if (mainWindow.myBtnClicked) {

                mainWindow.setMyPg(myProfile, myIdeas, myOpinions);
                mainWindow.myBtnClicked = false;
            }
        } catch (ClassNotFoundException | IOException e) {
            e.printStackTrace();
        }
    }
}

int i = 0;

Idea rcvIdea(int _ideaCode) throws ClassNotFoundException, IOException {
    objectOS.writeObject("sendIdea");
    objectOS.writeObject(_ideaCode);
    Idea returnValue = (Idea) objectIS.readObject();
    return returnValue;
}

Opinion rcvOpinion(int _opinionCode) throws ClassNotFoundException, IOException {
    objectOS.writeObject("sendOpinion");
    objectOS.writeObject(_opinionCode);
    return (Opinion) objectIS.readObject();
}

Profile rcvProfile(int _idCode) throws IOException, ClassNotFoundException {
    objectOS.writeObject("sendProfile");
    objectOS.writeObject(_idCode);
    return (Profile) objectIS.readObject();
}

void rcvNewIdeasCodes() throws ClassNotFoundException, IOException {
    objectOS.writeObject("sendNewIdeasCodes");
    newIdeasCodes = (ArrayList&lt;Integer&gt;) objectIS.readObject();
}

void rcvHotIdeasCodes() throws IOException, ClassNotFoundException {
    objectOS.writeObject("sendHotIdeasCodes");
    hotIdeasCodes = (ArrayList&lt;Integer&gt;) objectIS.readObject();
}

void rcvNewIdeas(int num) throws ClassNotFoundException, IOException {
    int i;
    rcvNewIdeasCodes();
    newIdeas = new ArrayList&lt;&gt;();
    if (num &lt;= newIdeasCodes.size()) {
        for (i = 0; i &lt; num; i++) {
            newIdeas.add(rcvIdea(newIdeasCodes.get(i)));
        }
    } else {
        for (i = 0; i &lt; newIdeasCodes.size(); i++) {
            newIdeas.add(rcvIdea(newIdeasCodes.get(i)));
        }
    }
}

void rcvHotIdeas(int num) throws ClassNotFoundException, IOException {
    int i;
    rcvHotIdeasCodes();
    hotIdeas = new ArrayList&lt;&gt;();
    if (num &lt;= hotIdeasCodes.size()) {
        for (i = 0; i &lt; num; i++) {
            hotIdeas.add(rcvIdea(hotIdeasCodes.get(i)));
        }
    } else {
        for (i = 0; i &lt; hotIdeasCodes.size(); i++) {
            hotIdeas.add(rcvIdea(hotIdeasCodes.get(i)));
        }
    }
}

void sendIdea(Idea _idea) throws IOException {
    objectOS.writeObject("rcvIdea");
    objectOS.writeObject(_idea);
}

void sendOpinion(Opinion _opinion) throws IOException {
    objectOS.writeObject("rcvOpinion");
    objectOS.writeObject(_opinion);
}

void sendProfile(Profile _profile) throws IOException {
    objectOS.writeObject(_profile);
}

boolean loginCheck() throws HeadlessException, NumberFormatException, IOException, ClassNotFoundException {
    objectOS.writeObject("loginCheck");// send command

    while (!mainWindow.loginBtnClicked) {
        continue;
    }
    mainWindow.loginBtnClicked = false;

    email = mainWindow.emailField.getText().trim();
    password = mainWindow.passwordField.getText().trim();
    objectOS.writeObject(email);
    objectOS.writeObject(password);

    boolean valid;
    valid = (boolean) objectIS.readObject();
    if (valid == false) {
        JOptionPane.showMessageDialog(mainWindow, "ID or Password is not correct");
        mainWindow.emailField.setText("");
        mainWindow.passwordField.setText("");
        return false;
    } else if (valid == true) {
        idCode = (int) objectIS.readObject();
        return true;
    } else {
        return false;
    }
}

void updateIdeaDetailMainPanel(Idea clickedIdea) throws ClassNotFoundException, IOException {
    ArrayList&lt;Opinion&gt; opinions = new ArrayList&lt;&gt;();
    for (int j = 0; j &lt; clickedIdea.opinionCode.size(); j++) {
        opinions.add(rcvOpinion(clickedIdea.opinionCode.get(j)));
    }
    mainWindow.ideaDetailFrame.updateMainPanel(opinions);
}

void updateIdeaDetailFrame(Idea clickedIdea) throws ClassNotFoundException, IOException {
    ArrayList&lt;Opinion&gt; opinions = new ArrayList&lt;&gt;();
    for (int j = 0; j &lt; clickedIdea.opinionCode.size(); j++) {
        opinions.add(rcvOpinion(clickedIdea.opinionCode.get(j)));
    }
    mainWindow.ideaDetailFrame = new IdeaDetailFrame(clickedIdea, opinions);
    mainWindow.ideaDetailFrame.setVisible(true);
}
}
</code></pre>

<p>Idea.class
    package data;</p>

<pre><code>import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

public class Idea implements Serializable {

private static final long serialVersionUID = 123123L;
public int idCode;
public int ideaCode;

public int plus = 0, minus = 0;

public String ideaName;
public String oneLineExp;
public String explanation;
public ArrayList&lt;Integer&gt; opinionCode;
public Date date;
public MyCanvas image;

int hotDegree;

public Idea(int _idCode,int _ideaCode, String _ideaName, String _oneLineExp, String _explanation, MyCanvas _image) {
    this(_idCode,_ideaName,_oneLineExp,_explanation,_image);
    ideaCode = _ideaCode;

}

public Idea(int _idCode, String _ideaName, String _oneLineExp, String _explanation, MyCanvas _image) {
    this(_idCode,_ideaName,_oneLineExp,_explanation);
    image = _image;
}

public Idea(int _idCode, String _ideaName, String _oneLineExp, String _explanation){
    idCode = _idCode;
    oneLineExp = new String(_oneLineExp);
    ideaName = new String(_ideaName);
    explanation = new String(_explanation);
    date = new Date();
    opinionCode = new ArrayList&lt;&gt;();
}

public void saveIdea() {
    FileOutputStream fos = null;
    ObjectOutputStream oos = null;

    try {
        fos = new FileOutputStream("Idea.dat");
        oos = new ObjectOutputStream(fos);

        oos.writeObject(this);
    } catch (IOException e1) {
        System.out.println("e1");
    }
}

void addOpinionCode(int _opinion) {
    opinionCode.add(opinionCode.size(), _opinion);
}

public void incPlus() {
    plus++;
}

public void incMinus() {
    minus++;
}

public int setHotDegree() {
    hotDegree = plus - minus + opinionCode.size() * 2;
    return hotDegree;
}
</code></pre>

<p>}</p>

<p>Opinion.class</p>

<pre><code>package data;

import java.io.Serializable;
import java.util.Date;

public class Opinion implements Serializable{
int idCode;
public int opinionCode;//the intrinsic code of this opinion

public int commentedIdeaCode;
public String opinion;
public Date date;
int plus, minus;

public Opinion(int _idCode,int _commentedIdeaCode, String _opinion){
    idCode = _idCode;
    commentedIdeaCode = _commentedIdeaCode;
    opinion = new String(_opinion);
    date = new Date();
    plus = 0;
    minus = 0;
}// Opinion(int _idCode,int _commentedIdeaCode, String _opinion)

public Opinion(int _idCode,int _opinionCode,int _commentedIdeaCode, String _opinion){
    this(_idCode, _commentedIdeaCode, _opinion);
    opinionCode = _opinionCode;
}//Opinion(int _idCode,int _opinionCode,int _commentedIdeaCode, String _opinion)

void incPlus(){
    plus++;
}

void incMinus(){
    minus++;
}
}
</code></pre>