wala / WALA

T.J. Watson Libraries for Analysis, with frontends for Java, Android, and JavaScript, and may common static program analyses
http://github.com/wala/WALA
Eclipse Public License 2.0
762 stars 223 forks source link

SourceDirCallGraph.java Exception java.lang.NoClassDefFoundError: IProgressMonitor #1411

Closed Eashurox closed 4 months ago

Eashurox commented 4 months ago

Hi, I wanted to use WALA for creating a call graph for a whole package or a Java project. I am referring to WALA-start/src/main/java/com/ibm/wala/examples/drivers/SourceDirCallGraph.java

When I am running the CGDirectory.java -> (same as) SourceDirCallGraph.java, I am receiving the following errors:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor at com.ibm.wala.cast.java.translator.jdt.ecj.ECJSourceLoaderImpl.getTranslator(ECJSourceLoaderImpl.java:62) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.loadAllSources(JavaSourceLoaderImpl.java:601) at com.ibm.wala.classLoader.ClassLoaderImpl.init(ClassLoaderImpl.java:506) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.init(JavaSourceLoaderImpl.java:612) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory.makeNewClassLoader(ECJClassLoaderFactory.java:31) at com.ibm.wala.classLoader.ClassLoaderFactoryImpl.getLoader(ClassLoaderFactoryImpl.java:63) at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:271) at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:204) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:87) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:73) at directory_analysis.CGDirectory.doit(CGDirectory.java:117) at directory_analysis.CGDirectory.main(CGDirectory.java:51) Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJSourceLoaderImpl.getTranslator(ECJSourceLoaderImpl.java:62) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.loadAllSources(JavaSourceLoaderImpl.java:601) at com.ibm.wala.classLoader.ClassLoaderImpl.init(ClassLoaderImpl.java:506) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.init(JavaSourceLoaderImpl.java:612) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory.makeNewClassLoader(ECJClassLoaderFactory.java:31) at com.ibm.wala.classLoader.ClassLoaderFactoryImpl.getLoader(ClassLoaderFactoryImpl.java:63) at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:271) at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:204) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:87) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:73) at directory_analysis.CGDirectory.doit(CGDirectory.java:117) at directory_analysis.CGDirectory.main(CGDirectory.java:51) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:419) at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192) at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)

I am getting this error from this line from the source code: IClassHierarchy cha = ClassHierarchyFactory.make(scope , new ECJClassLoaderFactory(scope.getExclusions()));

I ran the following cmd on the terminal: java -cp "lib/*" src/directory_analysis/CGDirectory.java -sourceDir ./CGTest1/src/example_analysis -mainClass LCGenTest

Following is my directory structure:

The project is neither a maven nor gradle project and I directly using the jars taken from maven repository.

JDK : 17.0.11 OS: macOS Sonoma 14.5 (aarch64)

Can you anyone please tell me how to fix this error?

msridhar commented 4 months ago

You are missing the relevant ECJ jars in your classpath. I just updated WALA-start to the latest WALA version (1.6.4). You can run the SourceDirCallGraph by cloning that repo and then running something like:

./gradlew -PmainClass=com.ibm.wala.examples.drivers.SourceDirCallGraph run --args="-sourceDir /tmp/srcTest -mainClass LFoo"

You must run on a JDK 17 JVM for things to work. If you want to run outside of Maven and Gradle, it will be a bit painful. I suggest running the above ./gradlew command with --debug and it will print out the full classpath used, which you can use to figure out which jars you need for the classpath. But, generally, life will be easier if you run via some build system like Maven or Gradle.

I will go ahead and close this but please let us know if you need more help.

Eashurox commented 4 months ago

Hi @msridhar, Thank You for your quick response.

I have clone the repo and run the above given cmd from the WALA-start repo. I am still getting an error which is as follows:

`> Task :run FAILED [-sourceDir, /Users/eashaan/eclipse-workspace/CGTest1/src/example_analysis, -mainClass, LCGTest] Exception in thread "main" com.ibm.wala.ipa.cha.ClassHierarchyException: factory.getLoader failed at com.ibm.wala.ipa.cha.ClassHierarchy.(ClassHierarchy.java:292) at com.ibm.wala.ipa.cha.ClassHierarchy.(ClassHierarchy.java:204) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:87) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:73) at com.ibm.wala.examples.drivers.SourceDirCallGraph.doit(SourceDirCallGraph.java:98) at com.ibm.wala.examples.drivers.SourceDirCallGraph.main(SourceDirCallGraph.java:60) Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.IMethodBinding.getMethodDeclaration()" because the return value of "org.eclipse.jdt.core.dom.MethodInvocation.resolveMethodBinding()" is null at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:1739) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visitNode(JDTJava2CAstTranslator.java:3845) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:1489) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:1513) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visitNodeOrNodes(JDTJava2CAstTranslator.java:3903) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.createBlock(JDTJava2CAstTranslator.java:1456) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:1461) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visitNode(JDTJava2CAstTranslator.java:3805) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:906) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.createClassDeclaration(JDTJava2CAstTranslator.java:529) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visitTypeDecl(JDTJava2CAstTranslator.java:434) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.visit(JDTJava2CAstTranslator.java:3779) at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.translateToCAst(JDTJava2CAstTranslator.java:273) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJSourceModuleTranslator$ECJAstToIR.acceptAST(ECJSourceModuleTranslator.java:158) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1143) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:739) at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:1049) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJSourceModuleTranslator.loadAllSources(ECJSourceModuleTranslator.java:258) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.loadAllSources(JavaSourceLoaderImpl.java:601) at com.ibm.wala.classLoader.ClassLoaderImpl.init(ClassLoaderImpl.java:506) at com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.init(JavaSourceLoaderImpl.java:612) at com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory.makeNewClassLoader(ECJClassLoaderFactory.java:31) at com.ibm.wala.classLoader.ClassLoaderFactoryImpl.getLoader(ClassLoaderFactoryImpl.java:63) at com.ibm.wala.ipa.cha.ClassHierarchy.(ClassHierarchy.java:271) ... 5 more

FAILURE: Build failed with an exception.

Build is successful using ./gradlew compileJava. But there is warning: Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

I am attaching the debug log, I am unable to understand why factory.getLoader failed?

P.S I am attaching the log file, when I added --debug option during the run. Can you please help me to figure this out? gradle_debug_log.txt

msridhar commented 4 months ago

@Eashurox this looks to me to be an issue with the source frontend and missing code, which can unfortunately cause it to crash. We've had issues like this for a while. See https://github.com/wala/WALA/issues/99 for further discussion. To confirm, maybe you can try analyze a simple test class with an empty main method. If that goes through, the problem is elsewhere.