Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

insert-annotations-to-source inserting annotations from Constructor at the field where it was non-present #216

@the1derer

Description

@the1derer

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(){

  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions