soot-oss / soot

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

soot.SootResolver$SootClassNotFoundException: couldn't find class: com.mycompany.app.CallGraphs (is your soot-class-path set properly?) #1927

Open omarjarkas1997 opened 2 years ago

omarjarkas1997 commented 2 years ago

Hello,

I'm trying to run the below call graph example in maven. My maven file tree is as follows with package com.mycompany.app

.
── my-app-1
           ├── src
            │      └── main
            │                  └── java
            │                              └── com
            │                                        └── mycompany
            │                                                       └── app
            │                                                            └── CallGraphExample.java
            │                                                            └── CallGraph.java
            │ 
            └── pom.xml 

Both CallGraphExample.java and CallGraph.java are under the same package com.mycompany.app;

CallGraphExample.java

package com.mycompany.app;

imports ...;

public class CallGraphExample 
{
    public static void main( String[] args ) {

        CallGraphs cg = new CallGraphs();

        System.out.println(cg.getClass().getName());
       List<String> argsList = new ArrayList<String>(Arrays.asList(args));
       argsList.addAll(Arrays.asList(new String[]{
               "-w",
               "-main-class",
               "com.mycompany.app.CallGraphs",//main-class
               "com.mycompany.app.CallGraphs",//argument classes
               "com.mycompany.app.A"            //
       }));

       PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {

        @Override
        protected void internalTransform(String phaseName, Map options) {
               CHATransformer.v().transform();
                       SootClass a = Scene.v().getSootClass("com.mycompany.app.A");

               SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
               CallGraph cg = Scene.v().getCallGraph();

               Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
               while (targets.hasNext()) {
                   SootMethod tgt = (SootMethod)targets.next();
                   System.out.println(src + " may call " + tgt);
               }
        }

       }));

        args = argsList.toArray(new String[0]);

        soot.Main.main(args);

    }
}

CallGraph.java

package com.mycompany.app;

public class CallGraphs
{
    public static void main(String[] args) {
        doStuff();
    }

    public static void doStuff() {
        new A().foo();
    }
}

class A
{
    public void foo() {
        bar();
    }

    public void bar() {
    }
}

Since both are under the same package. I change the arguments from testers.CallGraphs to com.mycompany.app.CallGraphs.

Despite making sure of the packages by printing System.out.println(cg.getClass().getName()); ---> com.mycompany.app.CallGraphs, i'm still getting couldn't find class: com.mycompany.app.CallGraphs (is your soot-class-path set properly?) error. the full error is below.

Soot.SootResolver$SootClassNotFoundException: couldn't find class: com.mycompany.app.CallGraphs (is your soot-class-path set properly?)
        at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:245)
        at soot.SootResolver.bringToHierarchy(SootResolver.java:221)
        at soot.SootResolver.bringToSignatures(SootResolver.java:292)
        at soot.SootResolver.bringToBodies(SootResolver.java:332)
        at soot.SootResolver.processResolveWorklist(SootResolver.java:171)
        at soot.SootResolver.resolveClass(SootResolver.java:141)
        at soot.Scene.loadClass(Scene.java:1069)
        at soot.Scene.loadClassAndSupport(Scene.java:1054)
        at soot.Scene.loadNecessaryClass(Scene.java:1836)
        at soot.Scene.loadNecessaryClasses(Scene.java:1848)
        at soot.Main.run(Main.java:241)
        at soot.Main.main(Main.java:141)
        at com.mycompany.app.CallGraphExample.main(CallGraphExample.java:59

Any help would be much appreciated.

jpstotz commented 2 years ago

The file name is CallGraph.java and your class name is CallGraphs (with an s at the end) -> Java class and file name do not fit together.

omarjarkas1997 commented 2 years ago

Thank you for your comment. That's a typo in the issue I logged. Apologies. The issue still exists.

PSKK-Git commented 1 month ago

Can I work on this issue?

StevenArzt commented 1 month ago

This seems to be a user error. I don't see that the original post specifies a process-dir in which Soot shall look for the classes.

Feel free to give an intro to Soot configuration to help the original user.