more interprocedural NullPointerException test cases

This commit is contained in:
Martin Hecker 2016-06-08 16:14:47 +02:00
parent 64c4034dca
commit 4905695e4a
5 changed files with 144 additions and 9 deletions

View File

@ -12,7 +12,12 @@ public class CallFieldAccess {
callIfNoException();
callDynamicIfException();
callDynamicIfNoException();
callIf2Exception();
callIf2NoException();
callDynamicIf2Exception();
callDynamicIf2NoException();
callGetException();
callDynamicGetException();
}
static B callIfException() {
@ -30,5 +35,32 @@ public class CallFieldAccess {
FieldAccessDynamic fad = new FieldAccessDynamic();
return fad.testIf(unknown, new B(), new B());
}
static B callIf2Exception() {
return FieldAccess.testIf2(unknown, null, null);
}
static B callIf2NoException() {
return FieldAccess.testIf2(unknown, new B(), null);
}
static B callDynamicIf2Exception() {
FieldAccessDynamic fad = new FieldAccessDynamic();
return fad.testIf2(unknown, null, null);
}
static B callDynamicIf2NoException() {
FieldAccessDynamic fad = new FieldAccessDynamic();
return fad.testIf2(unknown, new B(), null);
}
static B callGetException() {
B b = new B();
return FieldAccess.testGet(unknown, b);
}
static B callDynamicGetException() {
FieldAccessDynamic fad = new FieldAccessDynamic();
B b = new B();
return fad.testGet(unknown, b);
}
}

View File

@ -6,6 +6,6 @@ package cfg.exc.intra;
public class B {
int f;
B b;
public int f;
public B b;
}

View File

@ -108,8 +108,6 @@ public class FieldAccess {
if (unknown) {
b3.f = 17;
} else {
System.out.println();
}
return b3;

View File

@ -108,8 +108,6 @@ public class FieldAccessDynamic {
if (unknown) {
b3.f = 17;
} else {
System.out.println();
}
return b3;

View File

@ -23,6 +23,7 @@ import com.ibm.wala.cfg.exc.intra.IntraprocNullPointerAnalysis;
import com.ibm.wala.classLoader.ClassLoaderFactory;
import com.ibm.wala.classLoader.ClassLoaderFactoryImpl;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.core.tests.util.TestConstants;
import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
@ -66,14 +67,14 @@ public class NullPointerExceptionInterTest extends WalaTestCase {
public static void beforeClass() throws Exception {
cache = new AnalysisCache();
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA,
(new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), NullPointerExceptionInterTest.class.getClassLoader());
(new FileProvider()).getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS), NullPointerExceptionInterTest.class.getClassLoader());
ClassLoaderFactory factory = new ClassLoaderFactoryImpl(scope.getExclusions());
try {
cha = ClassHierarchy.make(scope, factory);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lcfg/exc/inter/CallFieldAccess");
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
CallGraphBuilder builder = Util.makeVanillaNCFABuilder(3, options, cache, cha, scope);
CallGraphBuilder builder = Util.makeNCFABuilder(1, options, cache, cha, scope);
cg = builder.makeCallGraph(options, null);
} catch (ClassHierarchyException e) {
throw new Exception();
@ -161,4 +162,110 @@ public class NullPointerExceptionInterTest extends WalaTestCase {
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertFalse(intraExplodedCFG.hasExceptions());
}
@Test
public void testIf2Exception() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIf2Exception()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertTrue(intraExplodedCFG.hasExceptions());
}
@Test
public void testDynamicIf2Exception() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIf2Exception()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertTrue(intraExplodedCFG.hasExceptions());
}
@Test
public void testIf2NoException() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIf2NoException()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertFalse(intraExplodedCFG.hasExceptions());
}
@Test
public void testDynamicIf2NoException() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIf2NoException()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertFalse(intraExplodedCFG.hasExceptions());
}
@Test
public void testGetException() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callGetException()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertTrue(intraExplodedCFG.hasExceptions());
}
@Test
public void testDynamicGetException() throws UnsoundGraphException, CancelException, WalaException {
MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicGetException()Lcfg/exc/intra/B");
IMethod m = cha.resolveMethod(mr);
Assert.assertEquals(1, cg.getNodes(mr).size());
final CGNode callNode = cg.getNodes(mr).iterator().next();
IR ir = cache.getIR(m);
InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG =
NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor());
ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode);
Assert.assertTrue(intraExplodedCFG.hasExceptions());
}
}