question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Devs: objects/UUID compare problems (inner rollbacks problem)

See original GitHub issue

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): shot_180113_143953

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

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: shot_180113_151814

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?): shot_180113_152232

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());
    }

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
LevelX2commented, Jan 13, 2018

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.

0reactions
JayDi85commented, Jun 16, 2019

Another one example of rollback and game state problem (#5835 with buyback ability – a few bugs have allowed this ability to work):

  • xmage uses copies of spells/abilities to play in many places, not original objects; shot_190616_214128
  • some objects can store inner data/statuses; shot_190616_213823
  • some objects forget to make copy and uses one object ref in all instances (e.g. same object in all game states – that’s ok for const objects): shot_190616_214606
  • some objects can change inner data and that’s data can be used outside of that objects: shot_190616_215033 shot_190616_215117
  • that’s wrong – you must use game state to store dynamic and shared data not inner objects: shot_190616_215210
Read more comments on GitHub >

github_iconTop Results From Across the Web

compare functionality for change management returns empty ...
Hello,. One of my customers is going to use DSM for change management for their 1500 LUW databases. I need to demonstrate this...
Read more >
Why I'm not fan of uuid datatype – select * from depesz;
First problem – UUID values are completely opaque. That means – uuids generated for table sessions will be indistinguishable from the ones ...
Read more >
How to Do UUID as Primary Keys the Right Way - DZone
UUID V4 or its COMB variant are great to mitigate varoius security, stability, and architectural issues, but be aware of various pitfalls ...
Read more >
PersistentObjectException: detached entity passed to persist ...
The solution is simple, just use the CascadeType.MERGE instead of CascadeType.PERSIST or CascadeType.ALL . I have had the same problem and CascadeType.
Read more >
Hibernate ORM 5.2.18.Final User Guide - Red Hat on GitHub
Hibernate is an Object/Relational Mapping solution for Java environments. ... Hibernate will issue an INSERT statement containing the hour, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found