Incomplete CallGraph using the Java Sourcecode Frontend || ZeroOneContainerCFABuilderFactory()?
While building a CallGraph out of the Jarfile (i.e. main.java compiled to main.class and packed into a jar) is complete, creating a callgraph using the source code frontend and running it with main.java results in a incomplete callgraph, i.e. really strange callgraph:
The actuall callgraph (created with the jar file ) looks like this:

The CallGraph created based only on main.java looks like this:

But as you can see it only recognises the main function and function out. but nothing else, even though, except for removing the line "package main;" and renaming the file main.java to bla.java (since otherwhise it did run into naming problems with the source front end) it is exactly the same class.
For building the 1st Callgraph instrunctions are as follows:

And for the incomplete one:

Did you try the SourceDirCallGraph class to build a source call graph? And could you post the code you are analyzing?
That is the code I am analyzing:
public class defaultMain{
public static void main(String[] args){ //normalFlow (0)
String wtf = "aha"; //normalFlow (1)
int output = 0;
int add = out(wtf); //callEntryFlow (2a) -> callLocalFlow (2b)
output = output + add; //-> callEntryFlow (5a) -> callExitFlow (5b)
finito(output);
propagate(3,wtf);
}
public static int out(String o){//normalFlow (3)
test(addOne(2),o);
testo(6);
testo(6);
finito(2);
return 1; //normalFlow (4)
}
public static void propagate(int i,String s){
int a = 0;
int b = 2;
a = a + b;
i = i + 1 + a;
test(i,s);
}
public static void finito(int nbr){
//lets say this is native func
dito(nbr);
}
public static void dito(int nbr){
}
public static void useless(int ul){
ul = ul +1;
}
public static int addOne(int nbr){
return nbr+1;
}
private static native void test(int nbr,String str);
private static native void testo(int nbr);
}
Running it with:
javac defaultMain.java
jar cfe defaultMain.jar defaultMain
(java -jar defaultMain.jar)
Does work, except for running it it will fail because there are native functions called, however running WALA with -appJar defaultMain.jar results in the compelete call graph, while running WALA on the source code (2) results in the incomplete one.
The result running it with SourceDirCallGraph (i.e. -sourceDir ".../JavaFiles/Default/" -mainClass "LdefaultMain" is the same incomplete Graph.
In case you need more info, just let me know, we could also have a quick call via zoom, teamviewer or whatever ;)
I did not find the exact problem but I can at least give you a hint on where the problem appears (if you didnt already find out).
So the problem is dependent on the builder used to build the call graph. For building the Callgraph with a jar (-appJar) we can use the builder Util.makeZeroCFABuilder:
builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope);
and then everything works as expected (referring to the complete callgraph). I, however wanted to be able to build the Callgraph with either a jar (-appJar), a source directory (-sourceDir) or even just a single java file (-file). As the ZeroCFABuilder seems not to work with a sourceDir (and file I think), I used the one proposed by the "SourceDirCallGraph" example: ZeroOneContainerCFABuilderFactory():
builder = new ZeroOneContainerCFABuilderFactory().make(options, new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory()), cha, scope);
This builder works for every type of input: jar, sourcedir and source file, HOWEVER it does NOT support building a callgraph if a native method is envolved and ALSO sometimes (due to really limited time I did not replicate) has a really strange behavior building a weird (totaly incomplete) callgraph. So this callgraph factory seems to be broken, or it is intended to build a call graph this way and I didnt reallise :D
@234235235 I recently fixed a serious bug with 0-1-container (#803). Not sure if you're still having this problem, but if so, could you try again with the latest WALA snapshot build (1.5.6-SNAPSHOT) to see if it persists?