ClassCastException VarSymbol to TypeElement, Android
Hello! I have exception like this: Caused by: java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$VarSymbol cannot be cast to javax.lang.model.element.TypeElement at io.realm.processor.RealmProcessor.process(RealmProcessor.java:97) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824) at com.sun.tools.javac.main.Main.compile(Main.java:439) ... 72 more
But unfortunately I can't imagine what can produce such Exception. I looked at the source and found the line which cause the exception, but didn't find the solution. Changes I made to project after which Exception appear: 1.Added custom constructor to some models(RealmObjects) 2. Added Roboelectric module for testing 3. Updated to AS 1.1.0 4. Added dagger(and removed after some time). 5. tried Realm 0.79. and returned back to 0.78. Please help with this issue! Maybe it is worth to add try\catch at that line and provide some more understandable message. Thanks
Hmm, that sounds odd. A few follow up questions
- What version of Java are you using to compile your app with?
- Which classes extend RealmObject or which one has a manual @RealmClass annotation?
- jdk1.7.0_55
- I didn't use @RealmClass annotation. All objects extend RealmObject. I tried adding @RealmClass to all classes but didn't remove extending from RealmObject - doesn't help.
Is it just normal public classes you extend or is there anything special about them?
Yes. All models are just public classes. They use Jackson annotations as well: @JsonIgnoreProperties(ignoreUnknown = true), @JsonIgnore. But actually that wasn't a problem.
Hi @mkovalyk Sorry for the late reply. Can you post your model class(es)?
So.. I think this issue isn't caused by wrong models. I resolved this issue by reverting commit and making all changes again ... Yesterday I wanted to try new Unit Test feature with Android studio 1.1.0.. So I change my android plugin to version 1.1.0 and add dependencies to junit: testCompile('junit:junit:4.11') { exclude module: 'hamcrest-core' } testCompile 'org.hamcrest:hamcrest-all:1.3'
and add annotation @Before to some method. After that everything become broken.
Actually I again migrated step-by-step from previous commit to broken one and discovered weird problem.. now problem appears when I migrated from 'com.google.android.gms:play-services-maps:6.5.87' to 'com.google.android.gms:play-services-maps:7.0.0'. I do not understand how it is connected.. Is it possible realm somehow conflict with other annotation processor( Dagger, Hugo, Jackson, Gson etc.)
It's possible, but it would show in the gradle logs. Do you see anything there related to such possible conflict?
Closing due to no response. Please reopen if you are still experiencing this issue.
I ran into the same issue upgrading to 0.81.1 from 0.80.3
Caused by: java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$VarSymbol cannot be cast to javax.lang.model.element.TypeElement
at io.realm.processor.RealmProcessor.process(RealmProcessor.java:125)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.too
I did not spend anytime researching into it, but reverted back to the 0.80.3 version.
I did a little more research and found the issue arises with the following dependencies:
compile 'io.realm:realm-android:0.81.1'
compile 'com.jakewharton:butterknife:7.0.0'
or
compile 'io.realm:realm-android:0.81.1'
compile 'com.jakewharton:butterknife:7.0.1'
So reverting back to 0.80.3 was misleading since I reverted butterknife back to version 6.1.0 and it worked again. It seems that upgrade butterknife to 7.0.0 or 7.0.1 causes Realm to break.