Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird 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 (which is just super(toCopy)) I sometimes don't get fields of the defaultDirection copied. Or not all of them. And using a Eclipse debugger is even stranger:

Debugger here I have clicked on the AbstractMailingDirections to be copied. See how defaultDirection.acceptanceTime is 17:00 in the toString print but shows up null in the field listing. If I click the defaultDirection, it's toString print will show the acceptanceTime field as null.

This is driving me nuts. Any ideas what could be causing this?

like image 649
vertti Avatar asked Oct 21 '22 11:10

vertti


1 Answers

Are these Hibernate entities (or JPA or similar)? In that case accessing the fields might brake the lazy loading magic & accessing it through getters might fix it.

like image 131
Jens Schauder Avatar answered Oct 27 '22 11:10

Jens Schauder