Annotation information missed after compiled with ECJ Compiler

81 views Asked by At

I found the bytecode compiled from ECJ compiler has the annotation information missing.

The source code decompiled from bytecode compiled by javac:

public class HelloWorldApp {

    @GetAction("/hello")
    public String sayHello() {
        return "Hello World!";
    }
}

The source code decompiled from bytecode compiled by ECJ:

public class HelloWorldApp {

    public String sayHello() {
        return "Hello World!";
    }
}

So clearly the annotation @GetAction("/hello") is missing from the bytecode compiled by ECJ (in memory compilation).

Anyone has encountered this issue before and get any clue?

Update with more information

Take a look at the following screenshot: enter image description here

So it is in the ASTNode.resolveAnnotations() methods line #797:

A) The state if ((method.tagBits & TagBits.AnnotationResolved) != 0) return annotations; will return null as annotations even

B) the source annotation @GetAction("/hello") is presented because

C) the this.annotations field is null and

D) the if condition (method.tagBits & TagBits.AnnotationResolved) != 0 evaluates to true

Updates 2

It looks like I captured the screen too early, so once process finished, I found the annotations information get stored:

enter image description here

However I still can't get the annotation information from the result file. Click here to download the bytecode file generated:

enter image description here

Note I am using ECJ 4.4.1:

<dependency>
  <groupId>org.eclipse.jdt.core.compiler</groupId>
  <artifactId>ecj</artifactId>
  <version>4.4.1</version>
</dependency>
1

There are 1 answers

0
Gelin Luo On BEST ANSWER

Problem solved! Just add the following lines:

    opt(map, OPTION_TargetPlatform, "1.6");

The issue is caused by default JDK version is 1.2 in ECJ, which does not support annotation