Description
When a subclass combines superclass overrides with interface default methods, JavaSlicer fails to build the System Dependence Graph and crashes while computing interprocedural actions. Programs that call super.greet() and rely on hello() supplied by an implemented interface trigger a NullPointerException, so no slice is produced.
Steps to Reproduce
- Save the following program as
SuperDefaultMetamorph.java:
interface Friendly {
default String hello(String name) {
return "Hello " + name;
}
}
class RootMetaGreeter {
public String greet(String name) {
return "Greetings " + name;
}
}
class HybridMetaGreeter extends RootMetaGreeter implements Friendly {
@Override
public String greet(String name) {
return hello(name) + " & " + super.greet(name);
}
}
public class SuperDefaultMetamorph {
public static void main(String[] args) {
RootMetaGreeter greeter = new HybridMetaGreeter();
String message = greeter.greet("World"); // slicing criterion
System.out.println(message);
}
}
- Run JavaSlicer:
java -jar sdg-cli-1.3.0-jar-with-dependencies.jar SuperDefaultMetamorph.java#24:message
Actual Behavior
JavaSlicer throws a NullPointerException during SDG construction:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "es.upv.mist.slicing.graphs.cfg.CFG.vertexSet()" because "cfg" is null
at es.upv.mist.slicing.graphs.sdg.InterproceduralActionFinder.initialValue(InterproceduralActionFinder.java:127)
at es.upv.mist.slicing.graphs.sdg.InterproceduralActionFinder.initialValue(InterproceduralActionFinder.java:25)
at es.upv.mist.slicing.graphs.BackwardDataFlowAnalysis.lambda$analyze$0(BackwardDataFlowAnalysis.java:33)
at java.base/java.util.LinkedHashMap$LinkedKeySet.forEach(LinkedHashMap.java:589)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092)
at es.upv.mist.slicing.graphs.BackwardDataFlowAnalysis.analyze(BackwardDataFlowAnalysis.java:33)
at es.upv.mist.slicing.graphs.sdg.InterproceduralActionFinder.save(InterproceduralActionFinder.java:41)
at es.upv.mist.slicing.graphs.sdg.SDG$Builder.dataFlowAnalysis(SDG.java:182)
at es.upv.mist.slicing.graphs.sdg.SDG$Builder.build(SDG.java:128)
at es.upv.mist.slicing.graphs.jsysdg.JSysDG$Builder.build(JSysDG.java:44)
at es.upv.mist.slicing.graphs.sdg.SDG.build(SDG.java:73)
at es.upv.mist.slicing.cli.Slicer.slice(Slicer.java:208)
at es.upv.mist.slicing.cli.Slicer.main(Slicer.java:286)
Expected Behavior
The slicer should construct CFG/SDG nodes for interface default methods and produce a valid slice that includes:
HybridMetaGreeter.greet
Friendly.hello default implementation
RootMetaGreeter.greet
This ensures the slice compiles and retains the polymorphic behaviour of the original program.
Root Cause
ClassGraph (see line ~136) contains a TODO noting that default method implementations in interfaces are ignored.
- Because the CFG for
Friendly.hello is never built, InterproceduralActionFinder receives a null CFG when it tries to analyse the call from HybridMetaGreeter.greet to the default method, leading to the NPE.
- Baseline code that avoids interface defaults (only class inheritance) slices successfully, confirming the failure is specific to default-method dispatch.
Suggested Fix
Ensure that interface default methods are incorporated into the class graph and receive CFGs during SDG construction. Once their CFGs exist, interprocedural analysis will no longer attempt to dereference a null cfg, and slices involving default-method dispatch will succeed.
Description
When a subclass combines superclass overrides with interface default methods, JavaSlicer fails to build the System Dependence Graph and crashes while computing interprocedural actions. Programs that call
super.greet()and rely onhello()supplied by an implemented interface trigger aNullPointerException, so no slice is produced.Steps to Reproduce
SuperDefaultMetamorph.java:Actual Behavior
JavaSlicer throws a
NullPointerExceptionduring SDG construction:Expected Behavior
The slicer should construct CFG/SDG nodes for interface default methods and produce a valid slice that includes:
HybridMetaGreeter.greetFriendly.hellodefault implementationRootMetaGreeter.greetThis ensures the slice compiles and retains the polymorphic behaviour of the original program.
Root Cause
ClassGraph(see line ~136) contains a TODO noting that default method implementations in interfaces are ignored.Friendly.hellois never built,InterproceduralActionFinderreceives anullCFG when it tries to analyse the call fromHybridMetaGreeter.greetto the default method, leading to the NPE.Suggested Fix
Ensure that interface default methods are incorporated into the class graph and receive CFGs during SDG construction. Once their CFGs exist, interprocedural analysis will no longer attempt to dereference a null
cfg, and slices involving default-method dispatch will succeed.