Bug 442938 - Exception Thrown While Processing Active Annotation
Summary: Exception Thrown While Processing Active Annotation
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-30 07:53 EDT by Dan Repik CLA
Modified: 2014-09-04 12:00 EDT (History)
1 user (show)

See Also:


Attachments
Contains Eclipse projects for annotation processor and consumer. (9.69 KB, application/x-zip-compressed)
2014-08-30 07:53 EDT, Dan Repik CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Repik CLA 2014-08-30 07:53:22 EDT
Created attachment 246571 [details]
Contains Eclipse projects for annotation processor and consumer.

Encountering the following exception when building project with active annotations.

java.lang.IllegalStateException
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:117)
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager ... rnal.jobs.Worker.run(Worker.java:54)

Compile error: IllegalStateException thrown: java.lang.IllegalStateException: Error reading configuration file

Steps to reproduce

In a project ExampleProcessor;

Created annotation;

package example;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target( ElementType.METHOD )
@Retention( RetentionPolicy.CLASS)
public @interface Example {

}

Created annotation processor file;

package example;

import java.io.*;
import javax.tools.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;

@SupportedAnnotationTypes(value= {"example.Example"})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class ExampleProcessor extends AbstractProcessor { 

  private Filer filer;

  public void init(ProcessingEnvironment env) {
    filer = env.getFiler();
  }

  public boolean process(Set elements, RoundEnvironment env) {
    // Discover anything marked with @SuppressWarnings
    for (Element element: env.getElementsAnnotatedWith(SuppressWarnings.class)) {
      if (element.getKind() == ElementKind.METHOD) {
        // For any methods we find, create an aspect:
        String methodName = element.getSimpleName().toString();
        String aspectText = 
          "public aspect Advise_"+methodName+" {\n"+
          "  before(): execution(* "+methodName+"(..)) {\n"+
          "    System.out.println(\""+methodName+" running\");\n"+
          "  }\n"+
          "}\n";
        try {
          JavaFileObject file = filer.createSourceFile("Advise_"+methodName, element);
          file.openWriter().append(aspectText).close();
          System.out.println("Generated aspect to advise "+methodName);
        } catch (IOException ioe) {
        }
      }
    }
    return true;
  }
}

This file is largely the same file as show in the blog;

http://andrewclement.blogspot.com/

with the only change being the SupportedAnnotationTypes annotation now refers to the custom annotation.

Then in a separate consumer project created;

import example.Example;

public class Demo {

  public static void main(String[] args) {
    callone();
    calltwo();
    callthree();
  }
 
  @Example
  public static void callone() {
    System.out.println("In callone");
  }
 
  public static void calltwo() {
    System.out.println("In calltwo");
  }

  @SuppressWarnings("rawtypes")
  public static void callthree() {
    System.out.println("In callthree");
  }
}

Again this is very similar to the demonstration project in the previously mentioned blog.  With the change being that the custom annotation is applied to the callone method.

On build the exception is thrown.
Comment 1 Andrew Clement CLA 2014-09-04 12:00:50 EDT
I have managed to recreate an illegalstateexception - but intermittently. Below the IllegalStateException it should show the original root cause. In both situations I could recreate it was a ZipException, one was:

java.util.zip.ZipException: invalid code lengths set

and the other was

java.util.zip.ZipException: invalid LOC header

Both of these seem to me like they are related to reading/writing the jar file in the same eclipse in some way but I can't quite pin it down yet. I'd suspected it was somebody not correctly closing the jar and it being updated whilst still open but a cursory check in the code seems to show it being closed correctly. Once I got into this situation I could just restart eclipse and it worked fine until I started updating the jar again by re-exporting the processor.  I am on mac which I know is more lenient on zip file locks compared to windows, I should perhaps try this on windows too.

One note, you've updated the processor SupportedAnnotationTypes but haven't changed the reference to SuppressWarnings inside the process() method - both will need updating.

Thanks for testing this functionality!