Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

AndroidAnnotationProcessor generates incorrect code when executed by javac compiler #471

Closed
eugenezh opened this issue Jan 23, 2013 · 5 comments
Labels

Comments

@eugenezh
Copy link

The problem is reproducible when a source file is compiled partially against previously compiled classes.

Consider an example:

@EActivity
class Base {
// class body
}

@EActivity
class Sub extends Base {
// class body
}

If both sources are compiled together, the generation result is as expected. If class Sub is changed and compiled against previously compiled Base class, the generated code lacks stuff that corresponds to Base class.

Debugging processor's sources shows that com.googlecode.androidannotations.model.ModelExtractor assumes that instances of javax.lang.model.type.DeclaredType have correctly overridden equals() and hashCode() methods, which is not true for some of javac's internal data structures (at least for com.sun.tools.javac.code.Type$ClassType).

Please consider method in com.googlecode.androidannotations.model.ModelExtractor:

private void extractAnnotations(AnnotationElementsHolder extractedModel, Set<DeclaredType> annotationTypesToCheck, TypeElement rootTypeElement, Element ancestorEnclosedElement)

The following check

if (annotationTypesToCheck.contains(annotationType)) {
// code
}

does not pass, because annotationTypesToCheck contains one instance of @EActivity mirror, and "annotationType" reference points to another instance of the same mirror.
This definitely looks like javac problem, as all instances of DeclaredType are expected to correctly define equals() and hashCode(), but unfortunately this is unlikely be fixed in the nearest future and there are many already existing JDK installations with this problem.

My proposal is that AndroidAnnotationProcessor in this case (and in all similar cases) should use either String types or wrapper classes with correctly defined equals() and hashCode()

Meanwhile this problem makes the annotation processor virtually unusable in combination with javac compiler in all situations when the code is compiled only partially.

Please do not hesitate to contact me directly at eugene.zhuravlev (at) jetbrains.com if you have any additional questions

@mathieuboniface
Copy link
Contributor

Hi Eugene o/

Thank you for all these great details ! I've reproduced successfully this weird behavior by running Maven from Eclipse in debug mode...

I will soon provide a fix based on your proposal !

Is that issue related to the support of Intellij IDEA ?

@CrazyCoder
Copy link

Is that issue related to the support of Intellij IDEA ?

Mathieu, yes, it was discovered from the IDEA user's feedback.

@mathieuboniface
Copy link
Contributor

This one has been fixed and packaged in the latest snapshot available here.

Glad to see that JetBrains engineers are more involved than some other ones :)

Let me know if you have any other issues.

@eugenezh
Copy link
Author

Hi Mathieu,

Thank you for all these great details ! I've reproduced successfully

You are welcome! With all these quick fixes from you more and more people
will benefit from the tool.

Is that issue related to the support of Intellij IDEA ?

Yes. One of implications for me personally is that there will be less
complains in our issue tracker that "we do not work with AndroidAnnotations
properly" :-)

Best regards,
Eugene Zhuravlev

On Thu, Jan 31, 2013 at 12:01 AM, Mathieu Boniface <notifications@github.com

wrote:

Hi Eugene o/

Thank you for all these great details ! I've reproduced successfully this
weird behavior by running Maven from Eclipse in debug mode...

I will soon provide a fix based on your proposal !

Is that issue related to the support of Intellij IDEA ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/471#issuecomment-12917690.

@pyricau
Copy link
Contributor

pyricau commented Feb 27, 2013

👍 👍 HAHAHA sorry about that :) .

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

No branches or pull requests

4 participants