Not implementing interface due to wrong cache
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
Yesterday I faced a problem where it happened:
if (EntityDao.class.isAssignableFrom(daoClass)) {
builder = ProxyBuilder.forClass(JAPTSYAndroidBaseEntityDao.class);
} else {
builder = ProxyBuilder.forClass(JAPTSYAndroidBaseDao.class);
}
builder.implementing(daoClass)
.constructorArgTypes(...)
.constructorArgValues(...);
builder.dexCache(DexCacheUtil.getDexCacheDir(appContext));
builder.handler(handler);
generatedDao = (D) builder.build();
if (!daoClass.isAssignableFrom(generatedDao.getClass())) {
//Bug!
Log.v("oh oh");
}
I have the following scenario:
public interface ShoppingListElementDao extends EntityDao<ShoppingListElement, ShoppingListElementId, EnParejaDaoFactory> {
}
public interface HomeTaskDao extends EntityDao<HomeTask, HomeTaskId, EnParejaDaoFactory> {
}
public abstract class JAPTSYAndroidBaseEntityDao<T, I, D extends IsDaoFactory> extends JAPTSYAndroidBaseDao<D>
implements EntityDao<T, I, D> {
}
I'm running the code above twice, one for each interface. With the first interface, it works properly but with the second (no matter the order) the implementing class is not properly being implemented.
Turns out that if I clear the dexCache directory when I detect that issue, it works. I have made this workaround:
//Bug
if (!bugDetected && !daoClass.isAssignableFrom(generatedDao.getClass())) {
//Bug!
Log.v("oh oh");
DexCacheUtil.clearDexCacheDir(appContext);
bugDetected = true;
} else {
bugDetected = false;
}
} while (bugDetected);
But this workaround is very annoying because time regenerating cache dir again takes too long.
Focusing the issue, it seems like the problem comes when both the interfaces and the superclass share same interface (in my case EntityDao) so it believes it's same cached class but it's not.
Thanks in advance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ProxyBuilder and DexCacheUtil calls shown in the issue, reproducing generation for ShoppingListElementDao and HomeTaskDao in both orders. Trace how implementing interfaces and the shared EntityDao superclass determine the dex-cache key. Done means both generated classes implement their requested interface without clearing the cache or retrying generation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100