From 0341eeebea854bec13429540b3debb0c030dd253 Mon Sep 17 00:00:00 2001 From: ngocpq Date: Wed, 12 Dec 2018 17:55:43 +0900 Subject: [PATCH] [fix-bug]: checking attrs is not null in method StackFrame:replaceLocalAttr( ) (#166) * fix-bug in StackFrame.replaceLocalAttr: attrs is null * add test-case --- src/main/gov/nasa/jpf/vm/StackFrame.java | 2 +- src/tests/gov/nasa/jpf/vm/StackFrameTest.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/tests/gov/nasa/jpf/vm/StackFrameTest.java diff --git a/src/main/gov/nasa/jpf/vm/StackFrame.java b/src/main/gov/nasa/jpf/vm/StackFrame.java index 0c642af..59c29ae 100644 --- a/src/main/gov/nasa/jpf/vm/StackFrame.java +++ b/src/main/gov/nasa/jpf/vm/StackFrame.java @@ -825,7 +825,7 @@ public abstract class StackFrame implements Cloneable { public void replaceLocalAttr (int index, Object oldAttr, Object newAttr){ assert index < stackBase && oldAttr != null && newAttr != null; - if (attrs == null){ + if (attrs != null){ attrs[index] = ObjectList.replace(attrs[index], oldAttr, newAttr); } } diff --git a/src/tests/gov/nasa/jpf/vm/StackFrameTest.java b/src/tests/gov/nasa/jpf/vm/StackFrameTest.java new file mode 100644 index 0000000..41a020d --- /dev/null +++ b/src/tests/gov/nasa/jpf/vm/StackFrameTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gov.nasa.jpf.vm; + +import gov.nasa.jpf.jvm.JVMStackFrame; +import gov.nasa.jpf.util.test.TestJPF; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +/** + * unit test for StackFrame operations + */ +public class StackFrameTest extends TestJPF { + + @Test + public void testReplaceLocalAttr() { + + MethodInfo mInfo = new MethodInfo("[methodName]", "()V", Modifier.PUBLIC, 2, 10); + JVMStackFrame frame = new JVMStackFrame(mInfo); + // Initialize local values and the stack frame + frame.push(1); + + String obj1 = "Attribute1"; + Class attrType = obj1.getClass(); + frame.addLocalAttr(0, obj1); + + final Object oldAttr = frame.getLocalAttr(0, attrType); + assertTrue(oldAttr != null && oldAttr == obj1); + + String obj2 = "Attribute2"; + frame.replaceLocalAttr(0, oldAttr, obj2); + + final Object newAttr = frame.getLocalAttr(0, attrType); + assertTrue(newAttr != null && newAttr == obj2); + } + + public static void main(String[] args) { + runTestsOfThisClass(null); + } +} -- 2.34.1