JavaSlicer icon indicating copy to clipboard operation
JavaSlicer copied to clipboard

Slicing doesn't seem to handle aliases correctly

Open thebesttv opened this issue 1 month ago • 2 comments

In the following program:

public class A {
    int o;
    
    public static void main(String[] args) {
        A x = new A();
        A y = x;
        x.o = 1;
        y.o = 2;
        System.out.println(x.o);
    }
}

slicing the x.o on the last line doesn't include the assignment to y.o:

public class A {

    int o;

    public static void main(String[] args) {
        A x = new A();
        x.o = 1;
        System.out.println(x.o);
    }
}

Demo link.

The sliced program doesn't seem to behave the same as the original one. I'm not sure if this is the intended behavior, could you explain a little? Thanks!

thebesttv avatar Nov 10 '25 06:11 thebesttv

This is a known issue, the slicer is missing a points-to analysis, to determine which variables (may) point to the same object, and thus be considered a dependency. The basic trivial implementation for this example is not difficult, but I won't be including it until we have a complete implementation that covers non-concurrent Java. I will leave this issue open to track progress.

cargaji avatar Nov 11 '25 09:11 cargaji

I've encountered a very similar problem in my usage of the slicer. Thank you @cargaji for confirming this issue and explaining the root cause. I really appreciate you keeping this open to track progress.

bystc avatar Nov 17 '25 11:11 bystc