Devs: objects/UUID compare problems (inner rollbacks problem)
See original GitHub issueContinue from #4402
You can’t compare UUID or objects by == operand. Need to use only obj.equals().
IntelliJ IDEA have inspections on that problems (use custom inspect settings to filter only needed data):

Current project have 72 warnings with == on objects (exported list to web page here):

BUT some xmage objects do not overrides Equals method and use default one, e.g. compare objects by == (compare refs, not data) .
As example, Player objects do not have Equals. All players data searched from game’s state object:

But game state can be changed and reverted. In particular, it’s saved to history every step by COPY (e.g. new state’s players is not equals to old one). And on rollback step can broke something if you save ref object to somewhere (is that can cause of “buggy rollback” function?) or if you have another thread (is xmage use one thread per game?):

I don’t known confirmed bug with that issue like with static filters (#4402). But devs have to be careful about this.
Howto fix that:
- Enable IDE warnings, find and replace
==toequalsfor xmage and UUID objects compare; - Add to each needed object overrided
equalsmethod. Example forPlayerImp.java(players with same ID will be equal):
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PlayerImpl obj = (PlayerImpl) o;
if (this.getId() == null || obj.getId() == null) {
return false;
}
return this.getId().equals(obj.getId());
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)

Top Related StackOverflow Question
Normally Players or MageObjects won’t be checked directly. They are compared by their UUID and if equals is used for the ID it works as intended.
So I don’t see that bugy anywhere. But indeed we have to replace == checks on the UUIDs with equals.
Another one example of rollback and game state problem (#5835 with
buybackability – a few bugs have allowed this ability to work):