Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using HashCodeComparator in class loading may and does cause instabilities #133

Closed
mohrm opened this issue Jan 26, 2017 · 4 comments
Closed

Comments

@mohrm
Copy link
Contributor

mohrm commented Jan 26, 2017

In ClassLoaderImpl, the method getClassFiles is responsible for retrieving all the module entries from a module and returning them as a set. For this, first the iterator is converted into a list and then this list is inserted into a TreeSet, using a comparator which compares two module entries by hash code (!).
I think this is highly fragile. The Java API doc clearly says that TreeSet relies on the used compareTo method being consistent with equals. In particular, TreeSet uses compareTo == 0 as eqality check. The used HashCodeComparator is not consistent with equals as there may be collisions. So, using a HashCodeComparator in getClassFiles may accidentally delete module entries.

I also think that there is a connection of this issue to #88. The dalvik front-end class DexClassLoaderImpl contains a method which is similar to getClassFiles (getDexFiles). The bad thing is that the DexModuleEntry class it processes does not implement hashCode or equals. I think this causes the flakiness, since now System.identityHashCode is used which is completely unpredictable.
One simple fix would be to implement hashCode and equals consistently for DexModuleEntry.

Another possible solution would be to not use TreeSet and HashCodeComparator but a LinkedHashSet.

I am in favor of the latter solution because it is more robust. I also don't think that it is really necessary to first unroll an iterator into a list and then insert all list items into a set, so removing this code would not only make it more robust but also faster and simpler.

@juliandolby @msridhar What do you think?

mohrm added a commit to joana-team/WALA that referenced this issue Jan 26, 2017
@juliandolby
Copy link
Contributor

juliandolby commented Jan 26, 2017 via email

@mohrm
Copy link
Contributor Author

mohrm commented Jan 26, 2017

@juliandolby What do you think about getting rid of HashCodeComparator, as proposed in #134? This not only seems more robust to me but also simpler and faster.

@juliandolby
Copy link
Contributor

juliandolby commented Jan 26, 2017 via email

@msridhar
Copy link
Member

Fixed by #134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants