soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.85k stars 706 forks source link

VisibilityLocalVariableAnnotationTag should consider annotation target correctly #2000

Open clearlove2077 opened 1 year ago

clearlove2077 commented 1 year ago

Describe the bug

Soot identifies the annotation whose target is type (TYPE_USE) as the VisibilityLocalVariableAnnotationTag, but it is wrong. We should consider the annotations with target LOCAL_VARIABLE as LocalVariableAnnotationTag. Please see the code example below.

Input file

@Retention(RUNTIME)
@Target({LOCAL_VARIBLE})
@interface A {}

@Retention(RUNTIME)
@Target({TYPE_USE})
@interface B {}
void method1() {
    @A String s = new String(); // cannot get VisibilityLocalVariableAnnotationTag
}

void method2() {
    @B String s = new String(); // can get VisibilityLocalVariableAnnotationTag, but @B is a TYPE_USE annotation
}

To reproduce

  1. Compile this source code file into bytecode;
  2. Use soot to analyze class file;
  3. Get the analyzed results.

Expected behavior

In the above code example, method1 does not have the LocalVariableAnnotationTag, but method2 has. However, we expect the opposite analysis results (method1 has, method2 does not).

Besides, considering the VisibilityParameterAnnotationTag which is similar to LocalVariableAnnotationTag as stated in the document, see the code example below:

@Retention(RUNTIME)
@Target({TYPE_USE})
@interface B {}

@Retention(RUNTIME)
@Target({PARAMETER})
@interface C {}

void method1(@B int p) {} // Cannot get ParameterAnnotationTag as expected, becase target of @B is TYPE_USE
void method2(@C int p) {} // Can get the ParameterAnnotationTag (target of @C is PARAMETER)

Soot constructs a VisibilityParameterAnnotationTag when its target is PARAMETER, not TYPE_USE. Hence, to keep the consistency, we need to consider the correct annotation target.