From: John Toman Date: Thu, 30 Aug 2018 22:31:57 +0000 (-0700) Subject: Fixes null captured parameters X-Git-Url: http://plrg.eecs.uci.edu/git/?p=jpf-core.git;a=commitdiff_plain;h=a0f52697142b667a2f86f72211768677d47f26a2 Fixes null captured parameters --- diff --git a/src/main/gov/nasa/jpf/vm/FunctionObjectFactory.java b/src/main/gov/nasa/jpf/vm/FunctionObjectFactory.java index de61be0..a96f932 100644 --- a/src/main/gov/nasa/jpf/vm/FunctionObjectFactory.java +++ b/src/main/gov/nasa/jpf/vm/FunctionObjectFactory.java @@ -61,8 +61,12 @@ public class FunctionObjectFactory { } else if (typeName.equals("boolean")) { fields.setBooleanValue(i, (Boolean)freeVarValues[i]); } else { - int val = ((ElementInfo)freeVarValues[i]).getObjectRef(); - fields.setReferenceValue(i, val); + if(freeVarValues[i] == null) { + fields.setReferenceValue(i, MJIEnv.NULL); + } else { + int val = ((ElementInfo)freeVarValues[i]).getObjectRef(); + fields.setReferenceValue(i, val); + } } } } diff --git a/src/tests/java8/LambdaTest.java b/src/tests/java8/LambdaTest.java index b6ec695..910876d 100644 --- a/src/tests/java8/LambdaTest.java +++ b/src/tests/java8/LambdaTest.java @@ -19,6 +19,8 @@ package java8; import gov.nasa.jpf.util.test.TestJPF; +import java.util.function.Supplier; + import org.junit.Test; /** @@ -294,4 +296,16 @@ public class LambdaTest extends TestJPF{ assertSame(fi1,fi2); } } + + @Test + public void testNullCaptureValues() { + if(verifyNoPropertyViolation()) { + Supplier provider = getStringProvider(null); + assertEquals(provider.get(), "It was null"); + } + } + + private Supplier getStringProvider(String object) { + return () -> object == null ? "It was null" : object; + } }