soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
586 stars 78 forks source link

Cannot parse annotations as annotation parameters #668

Open lptr opened 1 year ago

lptr commented 1 year ago

Annotations that take other annotations as parameters cause an exception.

Consider this code:

@Retention(RetentionPolicy.RUNTIME)
@interface Bela {
    String value();
}

@Retention(RetentionPolicy.RUNTIME)
@interface Alma {
    Bela value();
}

class MyType {
  @Alma(@Bela("tibor"))
  void myMethod();
}

The following causes the failure:

ClassType type = view.getIdentifierFactory().getClassType("MyType");
view.getClassOrThrow(type).getMethods();

Exception:

java.lang.IllegalArgumentException: cannot convert Object to (Soot-)Constant.
    at sootup.java.core.ConstantUtil.fromObject(ConstantUtil.java:70)
    at sootup.java.bytecode.frontend.AsmUtil.convertAnnotationValue(AsmUtil.java:376)
    at sootup.java.bytecode.frontend.AsmUtil.createAnnotationUsage(AsmUtil.java:343)
    at sootup.java.bytecode.frontend.AsmClassSource.convertAnnotation(AsmClassSource.java:82)
    at sootup.java.bytecode.frontend.AsmClassSource.lambda$resolveMethods$1(AsmClassSource.java:143)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    at sootup.java.bytecode.frontend.AsmClassSource.resolveMethods(AsmClassSource.java:146)
    at sootup.core.model.SootClass.lazyMethodInitializer(SootClass.java:78)
    at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:181)
    at sootup.core.model.SootClass.getMethods(SootClass.java:95)
    at sootup.java.core.JavaSootClass.getMethods(JavaSootClass.java:103)

SootUp version: 1.1.2.

lptr commented 1 year ago

The problem seems to be that ConstantUtil.fromObject() does not handle org.objectweb.asm.tree.AnnotationNode.

JonasKlauke commented 1 year ago

Thanks we will look into this. Mmh I thought we have implemented this. Did you try to use the current development version?

lptr commented 1 year ago

I see it with 1.1.2, is that ehat you mean by current version?

JonasKlauke commented 1 year ago

No the released version is the latest released version. I was talking about the current development state. To test this you have to build sootUp yourself and change your dependency version to 1.1.2-SNAPSHOT

To build it you can simply run: mvn install -DskipTests

Sometimes the source code frontend testcases do not work on some systems, so just skip the tests.

Hopefully you won't run in the current API changes 😅

swissiety commented 6 days ago

@marcus-h is this working with your recent rework ?