Repository: soot-oss/soot

Issue #1144: NullPointer Exception when running soot.tools.CFGViewer
Created: 2019-04-12T15:13:43Z
Steps to reproduce:
1.) sh runSoot.sh helloworld.apk out
Files used to reproduce:
runSoot.sh
#!/bin/bash

JAVA_CLASSPATH="/path/to/soot.jar"
ANDROID_JARS_PATH="/path/to/android/sdk"

APK_FILE=$1
SOOT_OUT_DIR=$2

SOOT_CMD="soot.tools.CFGViewer \
 --graph=CompleteBlockGraph \
 -d $SOOT_OUT_DIR \
 -android-jars $ANDROID_JARS_PATH \
 -allow-phantom-refs \
 -src-prec apk \
 -ire \
 -f J \
 -process-dir $APK_FILE"

java \
  -classpath ${JAVA_CLASSPATH} \
  -Xss50m \
  -Xmx1500m \
  ${SOOT_CMD}
Soot version: 3.3.0 
Command line:
-p jtp.printcfg graph-type:CompleteBlockGraph -d jimple -android-jars /usr/local/Android/Sdk/platforms/ -allow-phantom-refs -src-prec apk -ire -f J -process-dir original.apk
Max Memory:
1450MB
Stack trace:
[Thread-90] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
[Thread-92] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
[Thread-93] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
[Thread-94] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
[Thread-96] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
Exception in thread "Thread-93" Exception in thread "Thread-90" java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
[Thread-98] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
[Thread-97] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: null
java.util.concurrent.RejectedExecutionException: Task soot.PackManager$$Lambda$1/1565397985@767599a7 rejected from heros.solver.CountingThreadPoolExecutor@5f5effb0[Shutting down, pool size = 26, active threads = 21, queued tasks = 0, completed tasks = 5]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
	at heros.solver.CountingThreadPoolExecutor.execute(CountingThreadPoolExecutor.java:51)
	at soot.PackManager.runBodyPacks(PackManager.java:660)
	at soot.PackManager.runBodyPacks(PackManager.java:550)
	at soot.PackManager.runPacksNormally(PackManager.java:524)
	at soot.PackManager.runPacks(PackManager.java:419)
	at soot.Main.run(Main.java:269)
	at soot.Main.main(Main.java:141)
	at soot.tools.CFGViewer.main(CFGViewer.java:101)
java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at soot.tools.CFGViewer.print_cfg(CFGViewer.java:222)
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:84)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at soot.tools.CFGViewer.print_cfg(CFGViewer.java:222)
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:84)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:83)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at soot.tools.CFGViewer.print_cfg(CFGViewer.java:222)
	at soot.tools.CFGViewer.internalTransform(CFGViewer.java:84)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:120)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:125)
	at soot.PackManager.runBodyPacks(PackManager.java:1005)
	at soot.PackManager.lambda$runBodyPacks$0(PackManager.java:660)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Exception in thread "Thread-98" Exception in thread "Thread-97" Exception in thread "Thread-96"

Duplicate issue #1313: java.lang.RuntimeException when using CFGViewer command line option
Created: 2020-03-13T17:32:37Z
Steps to reproduce:
1.) javac -d ./target/classes -cp ./soot-3.3.0.jar ./src/main/java/staticAnalysis/FindPrimeFactor.java
2.) java -cp /Users/xyz/eclipse-workspace/staticAnalysis/sootclasses_j9-trunk-jar-with-dependencies.jar soot.tools.CFGViewer -cp "." -pp --graph=BriefUnitGraph --ir=grimp -p jb use-original-names:true FindPrimeFactor
Files used to reproduce:
import java.util.Arrays;
import java.util.List;
public class FindPrimeFactor {
public static void main(String []args) {
    List<Integer>a= Arrays.asList(12, 25, 18, 8); //happy path
    List<Integer> b = Arrays.asList(6, 2, 3, 2);
   System.out.println("INDEX "+findPrimeFactor(a,b));

}


public static int findPrimeFactor(List<Integer> a, List<Integer> b) throws IllegalArgumentException{
	   	
	try {
	    if (a == null) 
	        throw new NullPointerException();
	    }    	
	catch(NullPointerException e) {
		throw new IllegalArgumentException("List a cannot be null");
	}
	try {
		if (b == null) 
	        throw new NullPointerException();    	}
	catch(NullPointerException e) {
		throw new IllegalArgumentException("List b cannot be null");
	}
    for(int i = 0; i < b.size() && i < a.size(); i++) {
    	if(a.get(i)==null||b.get(i)==null|| b.get(i).equals(0))
    	 i++;
    	if(isPrime(b.get(i)) == true && a.get(i) % b.get(i) == 0) {
            return i;
        }
    }
	throw new IllegalArgumentException("List b doesn't have prime factor of any element in list a.");

}

public static boolean isPrime(int num) {
    int m,n,test=1;  
	if(num==1){
	test=2;
	testFunc(test);
		return false;
}
if(num<5){

	 m =6;
	 //return true;
}
else
{	 n = 7;
test =5;
	testFunc(test);

	for(int i = 2; i < num; i++) {
        if(num % i == 0) {
            return false;
        }
    }}
    return true;
}


public static void testFunc(int test){
    System.out.println("TEST HERE "+test);

}

}
Soot version: sootclasses_j9-trunk
Command line:
-cp . -pp -p jtp.printcfg graph-type:BriefUnitGraph -p jtp.printcfg ir:grimp -p jb use-original-names:true FindPrimeFactor
Max Memory:
2048MB
Stack trace:
java.lang.RuntimeException: Failed to convert <FindPrimeFactor: void testFunc(int)>
	at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:2062)
	at soot.SootMethod.retrieveActiveBody(SootMethod.java:402)
	at soot.PackManager$1.run(PackManager.java:1279)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.RuntimeException: 
Aborting: can't find classfile java.lang.invoke.StringConcatFactory
	at soot.Scene.getSootClass(Scene.java:1182)
	at soot.asm.AsmMethodSource.getClassFromScene(AsmMethodSource.java:349)
	at soot.asm.AsmMethodSource.toSootMethodRef(AsmMethodSource.java:1502)
	at soot.asm.AsmMethodSource.convertInvokeDynamicInsn(AsmMethodSource.java:1399)
	at soot.asm.AsmMethodSource.convert(AsmMethodSource.java:1813)
	at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:2060)
	... 5 more

Closing comment (2020-03-15T15:31:31Z): Might be related to #1144 and #1018 , while certainly looking a bit different.
@TealTulips could you debug your execution to pinpoint the cause of this NPE?