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

java.lang.ClassCastException when using the @Trace #799

Description

@athkalia

when I put the @trace annotation on method onCreateOptionsMenu I get the following exception:

java: Unexpected error. Please report an issue on AndroidAnnotations, with the following content: java.lang.ClassCastException: com.sun.codemodel.JVar cannot be cast to com.sun.codemodel.JStatement
at com.googlecode.androidannotations.helper.APTCodeModelHelper.removeBody(APTCodeModelHelper.java:188)
at com.googlecode.androidannotations.processing.TraceProcessor.process(TraceProcessor.java:63)
at com.googlecode.androidannotations.processing.ModelProcessor.process(ModelProcessor.java:102)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.processAnnotations(AndroidAnnotationProcessor.java:505)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:367)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:341)
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)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:178)
at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:376)
at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:279)
at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:191)
at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:163)
at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1087)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:798)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:846)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:761)
at org.jetbrains.jps.incremental.IncProjectBuilder.access$800(IncProjectBuilder.java:78)
at org.jetbrains.jps.incremental.IncProjectBuilder$BuildParallelizer$2.run(IncProjectBuilder.java:730)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:37)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Activity

  1. DayS commented on Nov 29, 2013

    @DayS
    Contributor

    Could you give us more information ?
    On which class do you use this annotation ? An activity or a fragment ? Are you using ActionBarSherlock or native classes ?

  2. athkalia commented on Nov 29, 2013

    @athkalia
    Author

    Hello,
    this is on an activity tagged @EActivity, and it is using the ActionBarSherlock. Also this class is annotated with @optionsmenu(R.menu.xxx). So it probably gets confused when the androidannnotations creates the onCreateOptionsMenu method to create the menu, but I also have a method like that on my activity in order to instantiate some MenuItems. Is there another way of instantiating MenuITems prior to AndroidAnnotations 3.0 ?

  3. DayS commented on Nov 29, 2013

    @DayS
    Contributor

    Just tested and AA crash when using both @Trace on onCreateOptionsMenu and @OptionsMenu on any kind of activity (native or ABS).. And the error is currently still here in 3.0-SNAPSHOT.

    Right now, the best way to handle this is to not using @Trace on onCreateOptionsMenu.

    If you really want to trace this method, you could :

    • comment the line @OptionsMenu(..) to allow enhanced class generation
    • copy the generated code for onCreateOptionsMenu into your original activity
    • uncomment the line @OptionsMenu(..)
  4. yDelouis commented on Nov 29, 2013

    @yDelouis
    Contributor

    I think this is fixed with the refactor. :)

  5. naixx commented on Dec 26, 2013

    @naixx
    Contributor

    Just stumbled upon similar issue with @Trace used in Activity.onCreate

    Unexpected error. Please report an issue on AndroidAnnotations, with the following content: java.lang.ClassCastException: com.sun.codemodel.JVar cannot be cast to com.sun.codemodel.JStatement
        at org.androidannotations.helper.APTCodeModelHelper.removeBody(APTCodeModelHelper.java:200)
        at org.androidannotations.processing.TraceProcessor.process(TraceProcessor.java:62)
        at org.androidannotations.processing.ModelProcessor.process(ModelProcessor.java:102)
    
  6. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    It should be fixed now

  7. naixx commented on Jan 10, 2014

    @naixx
    Contributor

    Great! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions