WALA icon indicating copy to clipboard operation
WALA copied to clipboard

failed to load impl class com.ibm.wala.cast.java.translator.polyglot.PolyglotSourceLoaderImpl

Open xiezhuokui opened this issue 1 year ago • 1 comments

Hi, when I am trying to build class hierarchy, I encountered this error.

Part of my code is,

            // For create the Analysis Scope
            ScopeConfiguration configuration = new ScopeConfiguration(mainInstance.projectPath, mainInstance.sourceType, mainInstance.exclusion);
            AnalysisScope scope = configuration.getAnalysisScope();

            // Build Class Hierarchy
            IClassHierarchy cha = ClassHierarchyFactory.make(scope);

The stacktrace is

java.lang.ClassNotFoundException: com.ibm.wala.cast.java.translator.polyglot.PolyglotSourceLoaderImpl
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
	at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Unknown Source)
	at com.ibm.wala.classLoader.ClassLoaderFactoryImpl.makeNewClassLoader(ClassLoaderFactoryImpl.java:106)
	at com.ibm.wala.classLoader.ClassLoaderFactoryImpl.getLoader(ClassLoaderFactoryImpl.java:61)
	at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:270)
	at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:203)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:85)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:71)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:28)
	at org.branson.slicer.Main.main(Main.java:106)
com.ibm.wala.ipa.cha.ClassHierarchyException: failed to load root <Primordial,Ljava/lang/Object> of class hierarchy
	at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:299)
	at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:203)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:85)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:71)
	at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:28)
	at org.branson.slicer.Main.main(Main.java:106)

I searched the whole project and found this. I think it is the reason why this error happened.

image

I've checked and noticed that there is no "PolyglotSourceLoaderImpl" in WALA project currently. And I found a similar SourceLoaderImpl called "JavaSourceLoaderImpl" at.com.ibm.wala.cast.java/1.6.2/com.ibm.wala.cast.java-1.6.2.jar!/com/ibm/wala/cast/java/loader/JavaSourceLoaderImpl.class". Is possible this is a potential bug? Or can you show me how to fix this? Thank you!

xiezhuokui avatar Oct 28 '23 05:10 xiezhuokui

You're right that there is a bug here. Unfortunately I don't know the right fix, as I'm not very familiar with this code. We have JDTSourceLoaderImpl and ECJSourceLoaderImpl and it's not clear what should be chosen by default in the code above. Maybe that code is old and should be removed or just fail fast? @juliandolby any ideas here?

In the meantime, does it work as a workaround to do something like this?

https://github.com/wala/WALA/blob/d7b408901e928aaf63c0d9f9b24a46403eb55d60/cast/java/ecj/src/main/java/com/ibm/wala/cast/java/ecj/util/SourceDirCallGraph.java#L99-L99

Where getLoaderFactory() is:

https://github.com/wala/WALA/blob/d7b408901e928aaf63c0d9f9b24a46403eb55d60/cast/java/ecj/src/main/java/com/ibm/wala/cast/java/ecj/util/SourceDirCallGraph.java#L68-L71

I'm assuming you're using ECJ. If you're using the JDT Eclipse plugin stuff there would be some slightly different code to use. Let me know if that works.

msridhar avatar Nov 01 '23 15:11 msridhar