0N/A/*
2362N/A * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4359628
0N/A * @summary Test fix for JDI: methods Accessible.is...() lie about array types
0N/A *
0N/A * @author Tim Bell
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
0N/A * @run compile -g AccessSpecifierTest.java
0N/A * @run main AccessSpecifierTest
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A /********** target program **********/
0N/A
0N/A
0N/A/** Sample package-private interface. */
0N/Ainterface AccessSpecifierPackagePrivateInterface {}
0N/A
0N/A/** Sample package-private class. */
0N/Aclass AccessSpecifierPackagePrivateClass {}
0N/A
0N/A/** Sample package-private class. */
0N/Aclass AccessSpecifierPackagePrivateClassTwo implements
0N/A AccessSpecifierPackagePrivateInterface {}
0N/A
0N/Aclass AccessSpecifierTarg {
0N/A private boolean z0;
0N/A boolean z1[]={z0}, z2[][]={z1};
0N/A
0N/A public byte b0;
0N/A byte b1[]={b0}, b2[][]={b1};
0N/A
0N/A protected short s0;
0N/A short s1[]={s0}, s2[][]={s1};
0N/A
0N/A int i0;
0N/A int i1[]={i0}, i2[][]={i1};
0N/A
0N/A private long l0;
0N/A long l1[]={l0}, l2[][]={l1};
0N/A
0N/A public char c0;
0N/A char c1[]={c0}, c2[][]={c1};
0N/A
0N/A protected float f0;
0N/A float f1[]={f0}, f2[][]={f1};
0N/A
0N/A double d0;
0N/A double d1[]={d0}, d2[][]={d1};
0N/A
0N/A Boolean Z0 = Boolean.TRUE;
0N/A Boolean Z1[]={Z0}, Z2[][]={Z1};
0N/A Byte B0 = new Byte ((byte)0x1f);
0N/A Byte B1[]={B0}, B2[][]={B1};
0N/A Character C0 = new Character ('a');
0N/A Character C1[]={C0}, C2[][]={C1};
0N/A Double D0 = new Double (1.0d);
0N/A Double D1[]={D0}, D2[][]={D1};
0N/A Float F0 = new Float (2.0f);
0N/A Float F1[]={F0}, F2[][]={F1};
0N/A Integer I0 = new Integer (8675309);
0N/A Integer I1[]={I0}, I2[][]={I1};
0N/A Long L0 = new Long (973230999L);
0N/A Long L1[]={L0}, L2[][]={L1};
0N/A String S0 = "A String";
0N/A String S1[]={S0}, S2[][]={S1};
0N/A Object O0 = new Object();
0N/A Object O1[]={O0}, O2[][]={O1};
0N/A
0N/A private static class U {}
0N/A protected static class V {}
0N/A public static class W {}
0N/A static class P {} // package private
0N/A
0N/A U u0=new U(), u1[]={u0}, u2[][]={u1};
0N/A V v0=new V(), v1[]={v0}, v2[][]={v1};
0N/A W w0=new W(), w1[]={w0}, w2[][]={w1};
0N/A P p0=new P(), p1[]={p0}, p2[][]={p1};
0N/A
0N/A private static interface StaticInterface {}
0N/A private static class ClassUsingStaticInterface
0N/A implements StaticInterface {}
0N/A
0N/A StaticInterface staticInterface_0 = new ClassUsingStaticInterface();
0N/A StaticInterface staticInterface_1[]={staticInterface_0};
0N/A StaticInterface staticInterface_2[][]={staticInterface_1};
0N/A
0N/A AccessSpecifierTarg a0, a1[]={a0}, a2[][]={a1};
0N/A
0N/A AccessSpecifierPackagePrivateClass ppc0=new AccessSpecifierPackagePrivateClass();
0N/A AccessSpecifierPackagePrivateClass ppc1[]={ppc0};
0N/A AccessSpecifierPackagePrivateClass ppc2[][]={ppc1};
0N/A
0N/A AccessSpecifierPackagePrivateInterface ppi0 =
0N/A new AccessSpecifierPackagePrivateClassTwo ();
0N/A AccessSpecifierPackagePrivateInterface ppi1[]={ppi0};
0N/A AccessSpecifierPackagePrivateInterface ppi2[][]={ppi1};
0N/A
0N/A public AccessSpecifierTarg() {
0N/A super();
0N/A }
0N/A
0N/A public void ready(){
0N/A System.out.println("Ready!");
0N/A }
0N/A
0N/A public static void main(String[] args){
0N/A System.out.println("Howdy!");
0N/A AccessSpecifierTarg my = new AccessSpecifierTarg();
0N/A my.ready();
0N/A System.out.println("Goodbye from AccessSpecifierTarg!");
0N/A }
0N/A}
0N/A
0N/A /********** test program **********/
0N/A
0N/Apublic class AccessSpecifierTest extends TestScaffold {
0N/A
0N/A private final static String debugeeName = "AccessSpecifierTarg";
0N/A
0N/A /** Known Accessible Information about the Debugee. */
0N/A private static final int NAME = 0;
0N/A private static final int ACCESS = 1;
0N/A private final static String primitives[][] = {
0N/A {"z", "private", "public", "public"},
0N/A {"b", "public", "public", "public"},
0N/A {"s", "protected", "public", "public"},
0N/A {"i", "package private", "public", "public"},
0N/A {"l", "private", "public", "public"},
0N/A {"c", "public", "public", "public"},
0N/A {"f", "protected", "public", "public"},
0N/A {"d", "package private", "public", "public"},
0N/A };
0N/A private final static String references[][] = {
0N/A {"java.lang.Boolean" , "public"},
0N/A {"java.lang.Character", "public"},
0N/A {"java.lang.Class" , "public"},
0N/A {"java.lang.Double" , "public"},
0N/A {"java.lang.Float" , "public"},
0N/A {"java.lang.Integer" , "public"},
0N/A {"java.lang.Long" , "public"},
0N/A {"java.lang.String" , "public"},
0N/A {"java.lang.Object" , "public"},
0N/A
0N/A {"AccessSpecifierTarg", "package private"},
0N/A {"AccessSpecifierPackagePrivateClass", "package private"},
0N/A {"AccessSpecifierPackagePrivateInterface", "package private"},
0N/A
0N/A {"AccessSpecifierTarg$StaticInterface", "private"},
0N/A
0N/A {"AccessSpecifierTarg$U", "private"},
0N/A {"AccessSpecifierTarg$V", "protected"},
0N/A {"AccessSpecifierTarg$W", "public"},
0N/A {"AccessSpecifierTarg$P", "package private"}
0N/A };
0N/A
0N/A AccessSpecifierTest (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new AccessSpecifierTest (args).startTests();
0N/A }
0N/A
0N/A /********** test core **********/
0N/A
0N/A private void testAccessible (String name, Accessible a,
0N/A boolean isPublic, boolean isProtected,
0N/A boolean isPrivate, boolean isPackagePrivate) {
0N/A System.out.println (" Testing: " + name + " modifiers = " +
0N/A Integer.toBinaryString(a.modifiers()));
0N/A if (a.isPublic() != isPublic) {
0N/A failure("**Name = " + name + " expecting: " + isPublic +
0N/A " isPublic() was: " + a.isPublic());
0N/A }
0N/A if (a.isPrivate() != isPrivate) {
0N/A failure("**Name = " + name + " expecting: " + isPrivate +
0N/A " isPrivate() was: " + a.isPrivate());
0N/A }
0N/A if (a.isProtected() != isProtected) {
0N/A failure("**Name = " + name + " expecting: " + isProtected +
0N/A " isProtected() is: " + a.isProtected());
0N/A }
0N/A if (a.isPackagePrivate() != isPackagePrivate) {
0N/A failure("**Name = " + name + " expecting: " + isPackagePrivate +
0N/A " isPackagePrivate() is: " + a.isPackagePrivate());
0N/A }
0N/A }
0N/A
0N/A protected void runTests() throws Exception {
0N/A /*
0N/A * Get to the top of ready()
0N/A */
0N/A startTo(debugeeName, "ready", "()V");
0N/A
0N/A ReferenceType rt = findReferenceType(debugeeName);
0N/A if (rt == null) {
0N/A throw new Exception ("ReferenceType not found for: " + debugeeName);
0N/A }
0N/A for (int i = 0; i < primitives.length; i++) {
0N/A for (int j = 0; j < 3; j++) {
0N/A String suffix = Integer.toString(j);
0N/A String fieldName = primitives[i][NAME] + suffix;
0N/A Field field = rt.fieldByName(fieldName);
0N/A if (field == null) {
0N/A throw new Exception ("Field not found for: " + fieldName);
0N/A }
0N/A
0N/A Type t = field.type();
0N/A if (t instanceof ReferenceType) {
0N/A ReferenceType reft = (ReferenceType)t;
0N/A if (primitives[i][ACCESS + j].equals("public")) {
0N/A testAccessible(reft.name(), reft,
0N/A true, false, false, false);
0N/A } else if (primitives[i][ACCESS + j].equals("protected")) {
0N/A testAccessible(reft.name(), reft,
0N/A false, true, false, false);
0N/A } else if (primitives[i][ACCESS + j].equals("private")) {
0N/A testAccessible(reft.name(), reft,
0N/A false, false, true, false);
0N/A } else if (primitives[i][ACCESS + j].equals("package private")) {
0N/A testAccessible(reft.name(), reft,
0N/A false, false, false, true);
0N/A }
0N/A } else {
0N/A System.out.println (" Skipping " + t +
0N/A " (primitive scalar type)");
0N/A }
0N/A }
0N/A }
0N/A
0N/A String brackets[] = {"[][]", "[]", ""};
0N/A
0N/A for (int i = 0; i < references.length; i++) {
0N/A for (int j = 0; j < 3; j++) {
0N/A String suffix = brackets[j];
0N/A String referenceName = references[i][NAME] + suffix;
0N/A ReferenceType refType = findReferenceType(referenceName);
0N/A if (refType == null) {
0N/A System.out.println ("Skipping " + referenceName +
0N/A " (not found)");
0N/A } else {
0N/A if (references[i][ACCESS].equals("public")) {
0N/A testAccessible(refType.name(), refType, true, false, false, false);
0N/A } else if (references[i][ACCESS].equals("protected")) {
0N/A testAccessible(refType.name(), refType, false, true, false, false);
0N/A } else if (references[i][ACCESS].equals("private")) {
0N/A testAccessible(refType.name(), refType, false, false, true, false);
0N/A } else if (references[i][ACCESS].equals("package private")) {
0N/A testAccessible(refType.name(), refType, false, false, false, true);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * resume the target listening for events
0N/A */
0N/A listenUntilVMDisconnect();
0N/A
0N/A /*
0N/A * deal with results of test
0N/A * if anything has called failure("foo") testFailed will be true
0N/A */
0N/A if (!testFailed) {
0N/A println("AccessSpecifierTest: passed");
0N/A } else {
0N/A throw new Exception("AccessSpecifierTest: failed");
0N/A }
0N/A }
0N/A}