Devs: objects/UUID compare problems (inner rollbacks problem)
- Dominant language
- Java
- Stars
- 2.4k
- Forks
- 940
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 160
Description
Continue 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](http://jaydi.ru/xmage/dev-compare/)):

**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 `==` to `equals` for xmage and UUID objects compare;
* Add to each needed object overrided `equals` method. Example for `PlayerImp.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());
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.