-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Description
When performing program slicing on a Java class with deeply nested static classes (targeting the result variable that accesses a value through a nested object chain), the automatically generated slice is incomplete and uncompilable.
Steps to Reproduce
Use the following Java code as the original input:
class Example {
static class Layer1 {
Layer2 layer2 = new Layer2();
}
static class Layer2 {
Layer3 layer3 = new Layer3();
}
static class Layer3 {
Layer4 layer4 = new Layer4();
}
static class Layer4 {
Layer5 layer5 = new Layer5();
}
static class Layer5 {
String deepValue = "deep_nesting_test";
}
public static void main(String[] args) {
Layer1 obj = new Layer1();
// Deep nesting that might cause issues in ObjectTree processing
String result = obj.layer2.layer3.layer4.layer5.deepValue;
System.out.println(result);
}
}
Trigger program slicing with the criterion: file: Example.java, line: 26, variable: result (line number corresponds to the String result = ... line in the original code).
Check the generated slice output.
Expected Result
The sliced code should retain all classes and fields necessary to resolve the nested object access chain (Layer1 → Layer2 → Layer3 → Layer4 → Layer5), as the result variable directly depends on:
The definition of each LayerX static class.
The field declarations and initializations (e.g., Layer2 layer2 = new Layer2()) in each class.
A correct slice would look like this (minimized but complete):
class Example {
static class Layer1 {
Layer2 layer2 = new Layer2();
}
static class Layer2 {
Layer3 layer3 = new Layer3();
}
static class Layer3 {
Layer4 layer4 = new Layer4();
}
static class Layer4 {
Layer5 layer5 = new Layer5();
}
static class Layer5 {
String deepValue = "deep_nesting_test";
}
public static void main(String[] args) {
Layer1 obj = new Layer1();
String result = obj.layer2.layer3.layer4.layer5.deepValue;
System.out.println(result);
}
}
Actual Result
The generated slice is missing critical class definitions (Layer2, Layer3, Layer4, Layer5), leading to compilation errors:
/*
This file was automatically generated as part of a slice with criterion
file: Example.java, line: 26, variable: result
Original file: D:\software\Metamorphic-slice-master\Metamorphic-slice-master\src\main\java\Example.java
*/
class Example {
static class Layer1 {
Layer2 layer2 = new Layer2();
}
public static void main(String[] args) {
Layer1 obj = new Layer1();
String result = obj.layer2.layer3.layer4.layer5.deepValue;
System.out.println(result);
}
}
Could you please help check if this issue is caused by a defect or limitation in the slicing tool itself? It would be greatly appreciated if you could share your insights on why the transitive dependencies in the nested object access chain were not retained.