Found bug in JUnitEntryPoints
When using junit4 annotations, the static method make(IClassHierarchy cha) can not return any entrypoint.
I found that isTestEntryPoint(TypeName typeName) might be wrong:
private static boolean isTestEntryPoint(TypeName typeName) {
// WALA uses $ to refers to inner classes. We have to replace "$" by "."
// to make it a valid class name in Java source code.
String javaName =
StringStuff.jvmToReadableType(typeName.getPackage() + "." + typeName.getClassName());
return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName);
}
For the class Lorg/abc/Main, typeName.getPackage() will return org.abc and delete the starting L. While jvmToReadableType depends on this L to parse the className. Without the starting L, jvmToReadableType will return an empty string.
So, I changed the method to the following:
private static boolean isTestEntryPoint(TypeName typeName) {
// WALA uses $ to refers to inner classes. We have to replace "$" by "."
// to make it a valid class name in Java source code.
String javaName = StringStuff.jvmToReadableType(
typeName.toString().replace('$', '.'));
return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName);
}
And it works.
Note that in my case, I have no inner classes to test. So I just changed the code by the comment.
Thanks for the report @el-nino2020! Could you submit a pull request with your fix? That would be great.
In fact, I just copied the source code of JUnitEntryPoints to my project and did the modification above, and it is sufficient for my use. I have not been looking into how to contributing to this project (nor do I have a good knowledge of WALA). Without testing, I think it is imporper to submit a PR. So I made an issue instead of a PR.
When using junit4 annotations, the static method
make(IClassHierarchy cha)can not return any entrypoint.I found that
isTestEntryPoint(TypeName typeName)might be wrong:private static boolean isTestEntryPoint(TypeName typeName) { // WALA uses $ to refers to inner classes. We have to replace "$" by "." // to make it a valid class name in Java source code. String javaName = StringStuff.jvmToReadableType(typeName.getPackage() + "." + typeName.getClassName()); return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName); }For the class
Lorg/abc/Main,typeName.getPackage()will returnorg.abcand delete the startingL.
Hm. I don't see where that is removed. I see it added here:
https://github.com/wala/WALA/blob/2f79c10f1188d4b2ef3904e2b5c39c0beebd9e5f/core/src/main/java/com/ibm/wala/types/TypeName.java#L314-L315
Ah, but that's in toString(). If the problem is from getPackage(), the package comes from the constructor and can be any atom.
I guess different representations may not be prefixed with L.