insert-annotation-to-source is inserting annotation that was present on Constructors to field where is was non-present.
"Step to reproduce" uses @SideEffectFree but using @RequiresNonNull or @Deprecated instead of @SideEffectFree also yields the same result i.e. Annotation at the wrong place. This means this bug is not isolated to just @SideEffectFree
To reproduce:
Test.java(Annotated)
import org.checkerframework.dataflow.qual.SideEffectFree;
class Test {
Object value;
@SideEffectFree
public Test(){
}
}
export CLASSPATH=checker-qual.jar
javac Test.java
extract-annotations Test.class
Test.jaif
package org.checkerframework.dataflow.qual:
annotation @SideEffectFree: @java.lang.annotation.Retention(value=RUNTIME) @java.lang.annotation.Target(value={METHOD,CONSTRUCTOR})
package :
class Test:
field value:
method <init>()V: @org.checkerframework.dataflow.qual.SideEffectFree
return:
Test.java(Unannotated)
class Test {
Object value;
public Test(){
}
}
insert-annotations-to-source -i=true Test.jaif Test.java
Result
import org.checkerframework.dataflow.qual.SideEffectFree;
class Test {
Object @SideEffectFree value;
public Test(){
}
}
Note:- This problem is only caused if @SideEffectFree is on Constructor. That is if there is @SideEffectFree on method there will be no error.
Example: (There will be no error in this case)
import org.checkerframework.dataflow.qual.SideEffectFree;
class Test {
Object value;
@SideEffectFree
public void test(){
}
}