mistupv / JavaSlicer

A program slicer for Java, based on the system dependence graph (SDG).
https://mist.dsic.upv.es/JavaSlicer/demo/
GNU Affero General Public License v3.0
52 stars 18 forks source link

Enums are unsupported #48

Closed WortelSoep closed 1 year ago

WortelSoep commented 3 years ago

This is probably a mistake/misunderstanding on my side, so apologies in advance :sweat_smile:.

So as a general question: I'm looking for a way to apply slicing to single unit tests taken from arbritary projects (I only want to know which statements in a unit test effect the assert statement and thus do not need a slice that contains anything else). Is it currently feasible to use JavaSDGSlicer for this?

I'm getting the feeling the project is not mature enough yet to support arbritary projects looking at other issues, but I'm still interested as there don't seem to be many (if any?) java slicers avaliable.

Now I have been trying to do this for jsoup (https://github.com/jhy/jsoup), by just running the running the slicer with the following command: java -jar sdg-cli-1.2.5-jar-with-dependencies.jar -c jsoup-master\src\test\java\org\jsoup\nodes\AttributeTest.java#12:attr -i jsoup-master\src -t SDG

However that results in this exception, I have no clue what causes it so I would appreciate any help.

Exception in thread "main" java.lang.NullPointerException at es.upv.mist.slicing.graphs.ClassGraph.mapKey(ClassGraph.java:268) at es.upv.mist.slicing.graphs.ClassGraph.addCallableDeclaration(ClassGraph.java:332) at es.upv.mist.slicing.graphs.ClassGraph$1.visit(ClassGraph.java:302) at es.upv.mist.slicing.graphs.ClassGraph$1.visit(ClassGraph.java:278) at com.github.javaparser.ast.body.MethodDeclaration.accept(MethodDeclaration.java:106) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$60(VoidVisitorAdapter.java:232) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at com.github.javaparser.ast.NodeList.forEach(NodeList.java:290) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:232) at com.github.javaparser.ast.body.EnumConstantDeclaration.accept(EnumConstantDeclaration.java:95) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$63(VoidVisitorAdapter.java:240) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at com.github.javaparser.ast.NodeList.forEach(NodeList.java:290) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:240) at com.github.javaparser.ast.body.EnumDeclaration.accept(EnumDeclaration.java:88) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$43(VoidVisitorAdapter.java:175) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at com.github.javaparser.ast.NodeList.forEach(NodeList.java:290) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:175) at com.github.javaparser.ast.CompilationUnit.accept(CompilationUnit.java:135) at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:624) at com.github.javaparser.ast.NodeList.accept(NodeList.java:282) at es.upv.mist.slicing.graphs.ClassGraph.buildVertices(ClassGraph.java:278) at es.upv.mist.slicing.graphs.ClassGraph.build(ClassGraph.java:245) at es.upv.mist.slicing.graphs.sdg.SDG$Builder.createClassGraph(SDG.java:164) at es.upv.mist.slicing.graphs.sdg.SDG$Builder.build(SDG.java:123) at es.upv.mist.slicing.graphs.sdg.SDG.build(SDG.java:71) at es.upv.mist.slicing.cli.Slicer.slice(Slicer.java:205) at es.upv.mist.slicing.cli.Slicer.main(Slicer.java:261)

-- Thanks for your time!

cargaji commented 3 years ago

Thanks for the interest in our slicer, but I'm afraid we're only in the early stages, and there are some common Java features missing (at least for now).

I've taken a look at the error, and it seems to be a lack of support for enums. It's in our roadmap for the near future, but I can't guarantee when it'll be ready.

Regarding Java slicers in general, you may want to check out WALA, as it contains a slicer for modern Java (11 at least).

Chaoshuai-Li commented 2 years ago

Is WALA available for slicing a shared variable? I want to analyze a concurrent program and I think it is important to slice a shared variable in order to analyze its assignments and method calls.

cargaji commented 1 year ago

Hi again, sorry for the late response. Right now, the latest version (not released, but the master version) has basic support for enums. If it doesn't work, please reopen the issue.