Unexpected Error on @AfterViews method #168

Closed
MattSenter opened this Issue Apr 19, 2012 · 12 comments

Comments

Projects
None yet
4 participants

This exception is occurring on an Activity I have annotated with an @AfterViews method.

java.lang.NullPointerException
    at org.eclipse.jdt.apt.core.internal.AptCompilationParticipant.addJava6GeneratedFile(AptCompilationParticipant.java:272)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl.addNewUnit(IdeProcessingEnvImpl.java:132)
    at org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeJavaSourceOutputStream.close(IdeJavaSourceOutputStream.java:72)
    at sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:301)
    at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:130)
    at java.io.OutputStreamWriter.close(OutputStreamWriter.java:216)
    at java.io.FilterWriter.close(FilterWriter.java:87)
    at java.io.BufferedWriter.close(BufferedWriter.java:248)
    at java.io.PrintWriter.close(PrintWriter.java:295)
    at com.googlecode.androidannotations.internal.codemodel.JFormatter.close(JFormatter.java:137)
    at com.googlecode.androidannotations.internal.codemodel.JPackage.build(JPackage.java:439)
    at com.googlecode.androidannotations.internal.codemodel.JCodeModel.build(JCodeModel.java:311)
    at com.googlecode.androidannotations.generation.CodeModelGenerator.generate(CodeModelGenerator.java:42)
    at com.googlecode.androidannotations.AndroidAnnotationProcessor.generateSources(AndroidAnnotationProcessor.java:513)
    at com.googlecode.androidannotations.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:328)
    at com.googlecode.androidannotations.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:299)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:813)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:432)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:364)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:329)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:301)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:134)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

My annotated method is pretty straight-forward:

@AfterViews
void afterViews() {
...
}

Looks like this might be an Eclipse issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=361378

Contributor

mathieuboniface commented Apr 19, 2012

Thank you very much kungfuters for the report !

Can you give us more informations on your development environnement ? Eclipse version, operating system, JVM/JDK variant etc...

Sure thing man. I'm on Eclipse Indigo (Service Release 1) Build Id: 20110916-0149 running on Mac OSX Lion using jdk1.6.0_31. I'm pretty sure this error isn't specific to your wonderful library because there are other annotation libraries that also encounter this problem on Eclipse. Still, if you know of a solution, I'd love to hear it! =)

Also using Maven 3.0.3 via m2e.

Contributor

pyricau commented Apr 19, 2012

Hello @kungfuters ,

I checked the AptCompilationParticipant code. This method causes the NPE :

    /**
     * Called during Java 6 annotation processing phase to register newly-generated files.
     * This information is then used in the Java 5 (post-compilation) phase when 
     * determining no-longer-generated files to delete.  The list of files is discarded
     * at the end of each build.
     */
    public void addJava6GeneratedFile(IFile file) {
        _java6GeneratedFiles.add(file);
    }

_java6GeneratedFiles is initially null, and is only modified in two places :

    /**
     * Files generated by Java 6 annotation processing during the current build.
     * These must be stored here in order to communicate between the Java 6 annotation
     * processing phase, which runs during Java compilation, and the Java 5 phase,
     * which runs afterwards.  This member is reinitialized during aboutToBuild()
     * and cleared in buildComplete().
     * 
     * Doing it this way implies that files can only be generated by Java 6 processing
     * during a build.  That is true as of 8/07.  If that changes, then this may need
     * to be stored as a thread local, or elsewhere entirely.
     */
    private HashSet<IFile> _java6GeneratedFiles = null;

    public int aboutToBuild(IJavaProject project) {
        if (AptConfig.isEnabled(project)) {
            // setup the classpath and make sure the generated source folder is on disk.
            AptPlugin.getAptProject(project).compilationStarted();
        }       
        _buildRound = 0; // reset
        // Note that for each project build, we blow away the last project's processed files.
        _processedFiles = new HashMap<IFile, CategorizedProblem[]>();
        _java6GeneratedFiles = new HashSet<IFile>();
        // TODO: (wharley) if the factory path is different we need a full build
        return CompilationParticipant.READY_FOR_BUILD;
    }

    private void buildComplete() {
        _processedFiles = null;
        _java6GeneratedFiles = null;
    }

From that, we can conclude that either aboutToBuild() is not called before calling addJava6GeneratedFile(), or buildComplete() is called too early.

So yes, this really looks like an Eclipse bug. Actually, I now realize that I've been investigating this eclipse java file already :) . A quick search on the mailing list, and here's the result : https://groups.google.com/d/topic/androidannotations/5CfEv66inaA/discussion

I'm not really sure this will help though..

Yessir, I ran across similar info. FWIW it just started working again. I'm sure there's some raindance voodoo that has to be executed in a certain order to clear things up, but I have not yet determined what that is. Oh Eclipse... =)

@MattSenter MattSenter closed this Apr 19, 2012

Contributor

pyricau commented Apr 20, 2012

Thanks for the info :)

This just happened to me. Restarting Eclipse made everything go back to normal. I upvoted the Eclipse bug.

Contributor

pyricau commented Aug 2, 2012

Ok :) . Could you provide the link to the Eclipse bug ?

It is the one mentioned previously in this issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=361378

Contributor

pyricau commented Aug 3, 2012

Sorry, I didn't see that.. I was tired, suffering from jetlag :)

Contributor

pyricau commented Aug 31, 2012

Damn. Happened to me :) . Restarting Eclipse did the trick.

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