Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/AccessSpecifierTest.java
38855 views
/*1* Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 435962826* @summary Test fix for JDI: methods Accessible.is...() lie about array types27*28* @author Tim Bell29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g AccessSpecifierTest.java32* @run main AccessSpecifierTest33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import com.sun.jdi.request.*;3738import java.util.*;3940/********** target program **********/414243/** Sample package-private interface. */44interface AccessSpecifierPackagePrivateInterface {}4546/** Sample package-private class. */47class AccessSpecifierPackagePrivateClass {}4849/** Sample package-private class. */50class AccessSpecifierPackagePrivateClassTwo implements51AccessSpecifierPackagePrivateInterface {}5253class AccessSpecifierTarg {54private boolean z0;55boolean z1[]={z0}, z2[][]={z1};5657public byte b0;58byte b1[]={b0}, b2[][]={b1};5960protected short s0;61short s1[]={s0}, s2[][]={s1};6263int i0;64int i1[]={i0}, i2[][]={i1};6566private long l0;67long l1[]={l0}, l2[][]={l1};6869public char c0;70char c1[]={c0}, c2[][]={c1};7172protected float f0;73float f1[]={f0}, f2[][]={f1};7475double d0;76double d1[]={d0}, d2[][]={d1};7778Boolean Z0 = Boolean.TRUE;79Boolean Z1[]={Z0}, Z2[][]={Z1};80Byte B0 = new Byte ((byte)0x1f);81Byte B1[]={B0}, B2[][]={B1};82Character C0 = new Character ('a');83Character C1[]={C0}, C2[][]={C1};84Double D0 = new Double (1.0d);85Double D1[]={D0}, D2[][]={D1};86Float F0 = new Float (2.0f);87Float F1[]={F0}, F2[][]={F1};88Integer I0 = new Integer (8675309);89Integer I1[]={I0}, I2[][]={I1};90Long L0 = new Long (973230999L);91Long L1[]={L0}, L2[][]={L1};92String S0 = "A String";93String S1[]={S0}, S2[][]={S1};94Object O0 = new Object();95Object O1[]={O0}, O2[][]={O1};9697private static class U {}98protected static class V {}99public static class W {}100static class P {} // package private101102U u0=new U(), u1[]={u0}, u2[][]={u1};103V v0=new V(), v1[]={v0}, v2[][]={v1};104W w0=new W(), w1[]={w0}, w2[][]={w1};105P p0=new P(), p1[]={p0}, p2[][]={p1};106107private static interface StaticInterface {}108private static class ClassUsingStaticInterface109implements StaticInterface {}110111StaticInterface staticInterface_0 = new ClassUsingStaticInterface();112StaticInterface staticInterface_1[]={staticInterface_0};113StaticInterface staticInterface_2[][]={staticInterface_1};114115AccessSpecifierTarg a0, a1[]={a0}, a2[][]={a1};116117AccessSpecifierPackagePrivateClass ppc0=new AccessSpecifierPackagePrivateClass();118AccessSpecifierPackagePrivateClass ppc1[]={ppc0};119AccessSpecifierPackagePrivateClass ppc2[][]={ppc1};120121AccessSpecifierPackagePrivateInterface ppi0 =122new AccessSpecifierPackagePrivateClassTwo ();123AccessSpecifierPackagePrivateInterface ppi1[]={ppi0};124AccessSpecifierPackagePrivateInterface ppi2[][]={ppi1};125126public AccessSpecifierTarg() {127super();128}129130public void ready(){131System.out.println("Ready!");132}133134public static void main(String[] args){135System.out.println("Howdy!");136AccessSpecifierTarg my = new AccessSpecifierTarg();137my.ready();138System.out.println("Goodbye from AccessSpecifierTarg!");139}140}141142/********** test program **********/143144public class AccessSpecifierTest extends TestScaffold {145146private final static String debugeeName = "AccessSpecifierTarg";147148/** Known Accessible Information about the Debugee. */149private static final int NAME = 0;150private static final int ACCESS = 1;151private final static String primitives[][] = {152{"z", "private", "public", "public"},153{"b", "public", "public", "public"},154{"s", "protected", "public", "public"},155{"i", "package private", "public", "public"},156{"l", "private", "public", "public"},157{"c", "public", "public", "public"},158{"f", "protected", "public", "public"},159{"d", "package private", "public", "public"},160};161private final static String references[][] = {162{"java.lang.Boolean" , "public"},163{"java.lang.Character", "public"},164{"java.lang.Class" , "public"},165{"java.lang.Double" , "public"},166{"java.lang.Float" , "public"},167{"java.lang.Integer" , "public"},168{"java.lang.Long" , "public"},169{"java.lang.String" , "public"},170{"java.lang.Object" , "public"},171172{"AccessSpecifierTarg", "package private"},173{"AccessSpecifierPackagePrivateClass", "package private"},174{"AccessSpecifierPackagePrivateInterface", "package private"},175176{"AccessSpecifierTarg$StaticInterface", "private"},177178{"AccessSpecifierTarg$U", "private"},179{"AccessSpecifierTarg$V", "protected"},180{"AccessSpecifierTarg$W", "public"},181{"AccessSpecifierTarg$P", "package private"}182};183184AccessSpecifierTest (String args[]) {185super(args);186}187188public static void main(String[] args) throws Exception {189new AccessSpecifierTest (args).startTests();190}191192/********** test core **********/193194private void testAccessible (String name, Accessible a,195boolean isPublic, boolean isProtected,196boolean isPrivate, boolean isPackagePrivate) {197System.out.println (" Testing: " + name + " modifiers = " +198Integer.toBinaryString(a.modifiers()));199if (a.isPublic() != isPublic) {200failure("**Name = " + name + " expecting: " + isPublic +201" isPublic() was: " + a.isPublic());202}203if (a.isPrivate() != isPrivate) {204failure("**Name = " + name + " expecting: " + isPrivate +205" isPrivate() was: " + a.isPrivate());206}207if (a.isProtected() != isProtected) {208failure("**Name = " + name + " expecting: " + isProtected +209" isProtected() is: " + a.isProtected());210}211if (a.isPackagePrivate() != isPackagePrivate) {212failure("**Name = " + name + " expecting: " + isPackagePrivate +213" isPackagePrivate() is: " + a.isPackagePrivate());214}215}216217protected void runTests() throws Exception {218/*219* Get to the top of ready()220*/221startTo(debugeeName, "ready", "()V");222223ReferenceType rt = findReferenceType(debugeeName);224if (rt == null) {225throw new Exception ("ReferenceType not found for: " + debugeeName);226}227for (int i = 0; i < primitives.length; i++) {228for (int j = 0; j < 3; j++) {229String suffix = Integer.toString(j);230String fieldName = primitives[i][NAME] + suffix;231Field field = rt.fieldByName(fieldName);232if (field == null) {233throw new Exception ("Field not found for: " + fieldName);234}235236Type t = field.type();237if (t instanceof ReferenceType) {238ReferenceType reft = (ReferenceType)t;239if (primitives[i][ACCESS + j].equals("public")) {240testAccessible(reft.name(), reft,241true, false, false, false);242} else if (primitives[i][ACCESS + j].equals("protected")) {243testAccessible(reft.name(), reft,244false, true, false, false);245} else if (primitives[i][ACCESS + j].equals("private")) {246testAccessible(reft.name(), reft,247false, false, true, false);248} else if (primitives[i][ACCESS + j].equals("package private")) {249testAccessible(reft.name(), reft,250false, false, false, true);251}252} else {253System.out.println (" Skipping " + t +254" (primitive scalar type)");255}256}257}258259String brackets[] = {"[][]", "[]", ""};260261for (int i = 0; i < references.length; i++) {262for (int j = 0; j < 3; j++) {263String suffix = brackets[j];264String referenceName = references[i][NAME] + suffix;265ReferenceType refType = findReferenceType(referenceName);266if (refType == null) {267System.out.println ("Skipping " + referenceName +268" (not found)");269} else {270if (references[i][ACCESS].equals("public")) {271testAccessible(refType.name(), refType, true, false, false, false);272} else if (references[i][ACCESS].equals("protected")) {273testAccessible(refType.name(), refType, false, true, false, false);274} else if (references[i][ACCESS].equals("private")) {275testAccessible(refType.name(), refType, false, false, true, false);276} else if (references[i][ACCESS].equals("package private")) {277testAccessible(refType.name(), refType, false, false, false, true);278}279}280}281}282283/*284* resume the target listening for events285*/286listenUntilVMDisconnect();287288/*289* deal with results of test290* if anything has called failure("foo") testFailed will be true291*/292if (!testFailed) {293println("AccessSpecifierTest: passed");294} else {295throw new Exception("AccessSpecifierTest: failed");296}297}298}299300301