-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Description
JavaSlicer crashes with IllegalStateException when attempting to slice code that contains abstract or native method declarations, even when these methods are not part of the slice criterion.
Steps to Reproduce
- Create a test file with abstract or native methods:
abstract class AbstractTest {
abstract int getValue();
native void nativeMethod();
}
class ConcreteTest extends AbstractTest {
int getValue() {
return 42;
}
native void nativeMethod();
public static void main(String[] args) {
ConcreteTest obj = new ConcreteTest();
int result = obj.getValue();
System.out.println(result); // Slice criterion
}
}Expected Behavior
The tool should skip abstract and native methods (which have no body) and successfully create a slice containing only the concrete implementation of getValue().
Actual Behavior
The tool crashes with:
Exception in thread "main" java.lang.IllegalStateException:
Graph creation is not allowed for abstract or native methods!
at es.upv.mist.slicing.utils.ASTUtils.lambda$getCallableBody$0(ASTUtils.java:111)
at es.upv.mist.slicing.graphs.cfg.CFGBuilder.visitCallableDeclarationBody(CFGBuilder.java:383)
Root Cause Hypothesis
The CFGBuilder attempts to visit all method declarations without checking if they have a body first. While ASTUtils.hasBody() exists to perform this check, it is not called before trying to access the method body.
Suggested Fix
Add a guard check in CFGBuilder before processing method declarations:
@Override
public void visit(MethodDeclaration n, Void arg) {
if (!ASTUtils.hasBody(n)) {
return; // Skip abstract/native methods
}
visitCallableDeclaration(n, arg);
}Metadata
Metadata
Assignees
Labels
No labels