You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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
changed the title
NullPointerException when creating an object in a static field.
Support for static fields and their initializations
Feb 5, 2021
I am getting a NullPointerException while building the SDG for a program that creates an object in a static field
MWE:
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:
The text was updated successfully, but these errors were encountered: