Java – strange copy constructor
I have two classes: abstractmailingdirections and directionload Both have a copy constructor as follows:
public AbstractMailingDirections(AbstractMailingDirections toCopy) { this.message = toCopy.message; this.defaultDirection = new DirectionLoad(toCopy.defaultDirection); for (final DirectionLoad dls : toCopy.directionLoads) { this.directionLoads.add(new DirectionLoad(dls)); } }
and
public DirectionLoad(DirectionLoad toCopy) { this.direction = toCopy.direction; this.transportationContract = toCopy.transportationContract; this.pickUpTime = toCopy.pickUpTime; this.acceptanceTime = toCopy.acceptanceTime; this.acceptanceLocation = toCopy.acceptanceLocation; this.information = toCopy.information; }
Now, when I call the mailingdirections copy constructor (it's just tocopy), I sometimes don't copy the fields of defaultdirection Or not all Using the eclipse debugger is even more strange:
Here, I click the abstractmailingdirections to be copied See defaultdirection. In toString printing How can the acceptancetime be 17:00, but is displayed as null in the field list If I click defaultdirection, its toString print will display the acceptance time field as null
It drives me crazy Any ideas that could lead to this situation?
Solution
Are these hibernate entities (or JPA or similar)? In this case, accessing the field may create delayed loading magic and accessing it through getters may fix it