Unexpected Package Name Behavior #812
-
When i load classes into a view, it seems like SootUp omits the longest common prefix in the package name. This is problematic when i try to build a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The directory structure in the out directory used in the next code snippet is pretty straight forward out |-> PackageTest.class |-> SubPackage |-> SubPackageTest.class public class PackageNameTest {
public static void main(String[] args) {
Path pathToSource = Paths.get("src/main/resources/sample_files/out/");
JavaLanguage language = new JavaLanguage(21);
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
inputLocations.add(new JavaClassPathAnalysisInputLocation(pathToSource.toString()));
JavaView view = new JavaView(inputLocations);
List<?> classes = (List<?>) view.getClasses();
}
} This is what the source files of the two classes look like:
package packageTest;
import packageTest.SubPackage.SubPackageTest;
public class PackageTest {
public PackageTest(){}
public void myFunction(){
SubPackageTest sub = new SubPackageTest();
System.out.println(sub.sub());
}
}
package packageTest.SubPackage;
public class SubPackageTest {
public SubPackageTest(){}
public String sub(){
return "sub";
}
} The two classes successfully compile together and keep their package declaration in the class files. Thank you for answering to my issue so quickly! |
Beta Was this translation helpful? Give feedback.
The packages are extracted by the root folder. In your example the root is out. Therefore, PackageTest has no package because it is directly in the root folder.
Set the root folder in the Inputlocation to the start of the package names.
You are missing the packageTest folder that contains everything. if the correct fully qualified name is
packageTest.Subpackage.SubPackageTest then your folder structure should look like this.
out
|-> packageTest
|-> PackageTest.class
|-> SubPackage
|-> SubPackageTest.class
SootUp is not consistent because the bytecode uses the correct fully qualified name because it is contained in the bytecode. Therefore, your inputlocation needs to point to a jar or a fo…