JavaSlicer icon indicating copy to clipboard operation
JavaSlicer copied to clipboard

Slice Tool Omits Critical Variable Modifications & Retains Undefined Variable When Slicing main-Defined Variable with Recursive Instance Methods

Open bystc opened this issue 1 month ago • 0 comments

1.Description The slicing tool has two critical issues when targeting callCount (in main): It omits key variable modification logic (constructor assignment of Counter.value and recursive count.value++). It retains an undefined variable caller in the generated slice, making the code invalid.

2.Steps to Reproduce Create Example.java with the following code:

public class Example {
    static class Counter {
        int value;
        Counter(int init) { this.value = init; } // Critical assignment
    }

    static class NestedCaller {
        void deepCall(int n, Counter count) {
            if (n > 0) {
                count.value++; // Critical recursive update
                deepCall(n - 1, count);
            }
        }
    }

    public static void main(String[] args) {
        Counter callCount = new Counter(0); // Target variable
        NestedCaller caller = new NestedCaller(); // Define caller
        caller.deepCall(100, callCount);
        System.out.println(callCount.value); // Slicing criterion (line 20)
    }
}

Run the tool with criterion: File Example.java → Line 20 → Variable callCount.

3.Expected Behavior The slice should retain: Counter constructor’s this.value = init (to initialize callCount.value), NestedCaller caller = new NestedCaller() (to define caller), count.value++ in deepCall (to track how callCount.value is updated), All original valid logic for callCount’s data flow.

4.Actual Behavior The generated slice is incomplete and invalid:

/*
	This file was automatically generated as part of a slice with criterion
	file: Example.java, line: 20, variable: callCount
	Original file: C:\Users\59829\Desktop\nju\Metamorphic-slice-master\Metamorphic-slice-master\src\main\java\Example.java
*/
public class Example {

    static class Counter {

        int value;

        Counter(int init) {
        } // MISSING: this.value = init
    }

    static class NestedCaller {

        void deepCall(int n, Counter count) {
            if (n > 0) {
                deepCall(n - 1, count);
            }
        } // MISSING: count.value++
    }

    public static void main(String[] args) {
        Counter callCount = new Counter(0);
        caller.deepCall(100, callCount); // ERROR: caller is undefined
        System.out.println(callCount.value);
    }
}

bystc avatar Oct 21 '25 06:10 bystc