soot-oss / soot

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

java.lang.NullPointerException when ... #1891

Open AhmedHamdyYassin12 opened 2 years ago

AhmedHamdyYassin12 commented 2 years ago

Steps to reproduce: 1.) ...

Files used to reproduce: ...

Soot version:

trunk

Command line:

-w -f n -allow-phantom-refs -x android.support. -x android.annotation. -process-dir D:\\Master\\Semister 4\\Mobile Security\\Tool\\apkFolder\\BBCNews.apk -android-jars C:\Users\97156\blueseal\BlueSeal\android-jars -src-prec apk -no-bodies-for-excluded

Max Memory:

1898MB

Stack trace:

java.lang.NullPointerException: Cannot invoke "String.split(String)" because the return value of "java.lang.System.getProperty(String)" is null
    at soot.JastAddJ.Program.initPaths(Program.java:350)
    at soot.SootResolver.<init>(SootResolver.java:88)
    at soot.Singletons.soot_SootResolver(Singletons.java:1456)
    at soot.SootResolver.v(SootResolver.java:93)
    at soot.Scene.tryLoadClass(Scene.java:693)
    at soot.Scene.loadBasicClasses(Scene.java:1354)
    at soot.Scene.loadNecessaryClasses(Scene.java:1433)
    at soot.Main.run(Main.java:243)
    at soot.Main.main(Main.java:147)
    at edu.buffalo.cse.blueseal.main.Main.main(Main.java:48)
jpstotz commented 2 years ago

What version of soot and what JRE/JDK version do you use?

HehBot commented 9 months ago

Soot version:

4.4.1

Command line:

-process-dir src/main/java rnd.samples.Test

Max memory:

1446 MB

Stack trace:

java.lang.NullPointerException: Cannot invoke "String.split(String)" because the return value of "java.lang.System.getProperty(String)" is null
    at soot.JastAddJ.Program.initPaths(Program.java:336)
    at soot.SootResolver.initializeProgram(SootResolver.java:99)
    at soot.SootResolver.getProgram(SootResolver.java:402)
    at soot.JastAddInitialResolver.formAst(JastAddInitialResolver.java:62)
    at soot.JavaClassSource.resolve(JavaClassSource.java:63)
    at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:274)
    at soot.SootResolver.bringToHierarchy(SootResolver.java:243)
    at soot.SootResolver.bringToSignatures(SootResolver.java:313)
    at soot.SootResolver.processResolveWorklist(SootResolver.java:198)
    at soot.SootResolver.resolveClass(SootResolver.java:155)
    at soot.Scene.loadClass(Scene.java:1016)
    at soot.Scene.loadClassAndSupport(Scene.java:1003)
    at soot.Scene.loadNecessaryClasses(Scene.java:1968)
    at soot.Main.run(Main.java:240)
    at soot.Main.main(Main.java:142)

Is there any resolution for this? I am facing the same issue with OpenJDK-21 as well as OpenJDK-17.

HehBot commented 9 months ago

I think the problem is in Program.java:332-350

      ...
      String[] bootclasspaths;
      if(options().hasValueForOption("-bootclasspath"))
        bootclasspaths = options().getValueForOption("-bootclasspath").split(File.pathSeparator);
      else
        bootclasspaths = System.getProperty("sun.boot.class.path").split(File.pathSeparator);
      for(int i = 0; i < bootclasspaths.length; i++) {
        classPaths.add(bootclasspaths[i]);
        //System.err.println("Adding classpath " + bootclasspaths[i]);
      }

      String[] extdirs;
      if(options().hasValueForOption("-extdirs"))
        extdirs = options().getValueForOption("-extdirs").split(File.pathSeparator);
      else
        extdirs = System.getProperty("java.ext.dirs").split(File.pathSeparator);
      for(int i = 0; i < extdirs.length; i++) {
        classPaths.add(extdirs[i]);
        //System.err.println("Adding classpath " + extdirs[i]);
      }
      ...

Both calls to System.getProperty return null for me.

Momo-Not-Emo commented 8 months ago

I met the same problem.

Got NPE for bootclasspaths = System.getProperty("sun.boot.class.path").split(File.pathSeparator);

soot version: 0b0293994fa393f7129f820912324013279693e9

I find a solution https://github.com/soot-oss/soot/issues/1466#issuecomment-705016104 and it works for me. I put both the class file and java source file in the same directory. After removed the java source file from that directory, the exception gone away!