Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for static fields and their initializations #46

Open
miguelvelezmj25 opened this issue Feb 5, 2021 · 2 comments
Open

Support for static fields and their initializations #46

miguelvelezmj25 opened this issue Feb 5, 2021 · 2 comments

Comments

@miguelvelezmj25
Copy link

I am getting a NullPointerException while building the SDG for a program that creates an object in a static field

MWE:

public class Scratch {
    public static final Scratch ONE = new Scratch();

    public Scratch() {}

    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

The public constructor here is redundant, but I also get the exception when the class has instance variables. Could you please take a look at this bug? Thanks!

Stack trace:

Exception in thread "main" java.lang.NullPointerException
	at es.upv.mist.slicing.graphs.CallGraph.findGraphNode(CallGraph.java:237)
	at es.upv.mist.slicing.graphs.CallGraph.addEdge(CallGraph.java:131)
	at es.upv.mist.slicing.graphs.CallGraph$2.createNormalEdge(CallGraph.java:230)
	at es.upv.mist.slicing.graphs.CallGraph$2.lambda$visit$1(CallGraph.java:177)
	at java.base/java.util.Optional.ifPresent(Optional.java:183)
	at es.upv.mist.slicing.graphs.CallGraph$2.visit(CallGraph.java:177)
	at es.upv.mist.slicing.graphs.CallGraph$2.visit(CallGraph.java:137)
	at com.github.javaparser.ast.expr.ObjectCreationExpr.accept(ObjectCreationExpr.java:118)
	at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$175(VoidVisitorAdapter.java:573)
	at java.base/java.util.Optional.ifPresent(Optional.java:183)
	at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:573)
	at com.github.javaparser.ast.body.VariableDeclarator.accept(VariableDeclarator.java:149)
	at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$79(VoidVisitorAdapter.java:274)
	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:274)
	at com.github.javaparser.ast.body.FieldDeclaration.accept(FieldDeclaration.java:118)
	at com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$31(VoidVisitorAdapter.java:154)
	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:154)
	at es.upv.mist.slicing.graphs.CallGraph$2.visit(CallGraph.java:144)
	at es.upv.mist.slicing.graphs.CallGraph$2.visit(CallGraph.java:137)
	at com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.accept(ClassOrInterfaceDeclaration.java:100)
	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:138)
	at com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:623)
	at com.github.javaparser.ast.NodeList.accept(NodeList.java:282)
	at es.upv.mist.slicing.graphs.CallGraph.buildEdges(CallGraph.java:137)
	at es.upv.mist.slicing.graphs.CallGraph.build(CallGraph.java:104)
	at es.upv.mist.slicing.graphs.sdg.SDG$Builder.createCallGraph(SDG.java:146)
	at es.upv.mist.slicing.graphs.sdg.SDG$Builder.build(SDG.java:114)
	at es.upv.mist.slicing.graphs.sdg.SDG.build(SDG.java:73)
	at es.upv.mist.slicing.cli.Slicer.slice(Slicer.java:274)
	at es.upv.mist.slicing.cli.Slicer.main(Slicer.java:335)
@cargaji
Copy link
Collaborator

cargaji commented Feb 5, 2021

We're currently in the process of adding OO features to the slicer, and static fields are far down the list. I'm afraid this slicer still has at least a month to reach a minimum level of usability, regarding Java features. I'll leave this issue open to track the progress on static fields and their initialization.

If you want the specifics, we don't know when the static fields are initialized, as that depends on where was the first reference to that class in any given execution. Thus, there's no clear place in the inter-procedural control-flow where the initialization happens.

@cargaji cargaji changed the title NullPointerException when creating an object in a static field. Support for static fields and their initializations Feb 5, 2021
@miguelvelezmj25
Copy link
Author

Thanks for the response! I am really looking forward to using this in my own research projects.

@cargaji cargaji mentioned this issue May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants