1 // Tags: JDK1.1 |
|
2 |
|
3 // Copyright (C) 2003 Free Software Foundation, Inc. |
|
4 // Contributed by Mark Wielaard (mark@klomp.org) |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 package gnu.testlet.java.lang.reflect.AccessibleObject; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 import java.lang.reflect.*; |
|
28 import java.io.*; |
|
29 |
|
30 public class accessible implements Testlet |
|
31 { |
|
32 public void test (TestHarness harness) |
|
33 { |
|
34 try |
|
35 { |
|
36 Class cl_class = Class.forName("java.lang.ClassLoader"); |
|
37 |
|
38 // There is a protected no-argument ClassLoader() constructor. |
|
39 Class[] params = new Class[0]; |
|
40 Constructor cl_cons = cl_class.getDeclaredConstructor(params); |
|
41 harness.check(!cl_cons.isAccessible()); |
|
42 |
|
43 cl_cons.setAccessible(true); |
|
44 harness.check(cl_cons.isAccessible()); |
|
45 |
|
46 // Get a new Constructor to check that it isn't accessible. |
|
47 cl_cons = cl_class.getDeclaredConstructor(params); |
|
48 harness.check(!cl_cons.isAccessible()); |
|
49 |
|
50 // ClassLoader.findLoadedClass(String) is a protected method. |
|
51 params = new Class[1]; |
|
52 params[0] = Class.forName("java.lang.String"); |
|
53 Method m = cl_class.getDeclaredMethod("findLoadedClass", params); |
|
54 harness.check(!m.isAccessible()); |
|
55 |
|
56 m.setAccessible(true); |
|
57 harness.check(m.isAccessible()); |
|
58 |
|
59 // Get a new Member to check that is isn't accessible. |
|
60 m = cl_class.getDeclaredMethod("findLoadedClass", params); |
|
61 harness.check(!m.isAccessible()); |
|
62 |
|
63 // Take some random protected field from DataInputStream. |
|
64 DataInputStream dis |
|
65 = new DataInputStream(new ByteArrayInputStream(new byte[0])); |
|
66 Class dis_cl = dis.getClass(); |
|
67 Class fis_cl = dis_cl.getSuperclass(); |
|
68 Field dis_f = fis_cl.getDeclaredField("in"); |
|
69 harness.check(!dis_f.isAccessible()); |
|
70 |
|
71 dis_f.setAccessible(true); |
|
72 harness.check(dis_f.isAccessible()); |
|
73 |
|
74 // Get a new Field to check that is isn't accessible. |
|
75 dis_f = fis_cl.getDeclaredField("in"); |
|
76 harness.check(!dis_f.isAccessible()); |
|
77 |
|
78 } |
|
79 catch (Throwable t) |
|
80 { |
|
81 harness.debug(t); |
|
82 harness.fail(t.toString()); |
|
83 } |
|
84 } |
|
85 } |
|