Why is Soot always saying That the class I want to load is a phantom class, even when it does not exist

907 views Asked by At

This soot class loads a class and prints the number of methods. When I give the correct name of the class I want to load it says that the class is phantom. Also when the class does not exist it gives the same message. I do not know what I am doing wrong.

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

             List<String> projectPaths;
            String classPath;
             String highLevelPackageName;
            classPath = "C:\\Users\\Alastair\\workspace1\\Interview\\bin";

            projectPaths = new ArrayList<String>();

            projectPaths.add(classPath);

            Options.v().set_allow_phantom_refs(true);
            Options.v().set_whole_program(true);
            Options.v().set_app(true);
            Options.v().set_no_bodies_for_excluded(true);
            Options.v().set_process_dir(projectPaths);

            String previousClassPath = Scene.v().getSootClassPath();
            previousClassPath += ";" + classPath;

            Scene.v().setSootClassPath(previousClassPath);



            SootClass sootClass = Scene.v().loadClassAndSupport("Diagonal.class");

            sootClass.setApplicationClass();
            System.out.println(sootClass.getMethodCount());
    }
}

This is the class I am trying to load.

public class Diagonal {

    public static void main(String args[]) {
        diagonal();
        lefttriangle();
        righttriangle();
        tree();
    }

    public static void diagonal() {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                if (i == j) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }

    public static void lefttriangle() {
        for(int i=0;i<6;i++){
            for(int j=0;j<6;j++){
                if(j<=i){
                    System.out.print("*");
                }
                else{
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }

    public static void righttriangle(){
        for(int i=0;i<7;i++){
            for(int j=7;j>0;j--){
                if(i<j){
                    System.out.print(" ");
                }else{
                    System.out.print("*");
                }

            }
            System.out.println("");
        }
    }

    public static void tree(){
        for(int i=1;i<=7;i++){
            for(int j=7;j>i;j--){
                    System.out.print(" ");
            }
            for(int j = 1; j < i*2; j++){

                    System.out.print("*");

            }
            System.out.println("");
        }
    }



}
1

There are 1 answers

0
Eric Bodden On

Phantom classes are implicitly created models of classes that do not exist on Soot's classpath. To get rid of this problem, make sure that the class you are referencing is on Soot's classpath.