2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.test.vm.reflection;
20 import gov.nasa.jpf.util.test.TestJPF;
22 import org.junit.Test;
24 public class ReflectionTest extends TestJPF {
26 static class MyClass {
31 // compilation will cause a warning about internal proprietary API that cannot be suppressed, but we have to test this
32 // since it is still used by standard libs
34 Class<?> callerCls = sun.reflect.Reflection.getCallerClass(0); // that would be getCallerClass()
35 System.out.println("-- getCallerClass(0) = " + callerCls);
36 assertTrue(callerCls.getName().equals("sun.reflect.Reflection"));
38 callerCls = sun.reflect.Reflection.getCallerClass(1); // foo()
39 System.out.println("-- getCallerClass(1) = " + callerCls);
40 assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.vm.reflection.ReflectionTest$MyClass"));
42 callerCls = sun.reflect.Reflection.getCallerClass(2); // bar()
43 System.out.println("-- getCallerClass(2) = " + callerCls);
44 assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.vm.reflection.ReflectionTest$MyClass"));
46 callerCls = sun.reflect.Reflection.getCallerClass(3); // callIt()
47 System.out.println("-- getCallerClass(3) = " + callerCls);
48 assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.vm.reflection.ReflectionTest"));
50 // <2do> should also test Method.invoke skipping
55 MyClass o = new MyClass();
60 public void testCallerClass() {
61 if (verifyNoPropertyViolation()){