JDK-6648344 : (reflect spec) State default of isAccessible for reflective objects
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-01-08
  • Updated: 2017-05-16
  • Resolved: 2009-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b75Fixed
Description
Neal Gafter has observed that the core reflection documentation does not explicitly state what the default value of isAccessible.  Presumably the default should be false.

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1255468137 25200 # Node ID 9d240dbadaa3e03605b7a0baf195f7fd552d2528 # Parent f6770138c0fa254e6f551a594f02dc2d1971f4a9 6648344: (reflect spec) State default of isAccessible for reflective objects Reviewed-by: alanb --- a/src/share/classes/java/lang/reflect/AccessibleObject.java Sat Oct 10 10:14:51 2009 +0100 +++ b/src/share/classes/java/lang/reflect/AccessibleObject.java Tue Oct 13 14:08:57 2009 -0700 @@ -43,6 +43,8 @@ import java.lang.annotation.Annotation; * permits sophisticated applications with sufficient privilege, such * as Java Object Serialization or other persistence mechanisms, to * manipulate objects in a manner that would normally be prohibited. + * + * <p>By default, a reflected object is <em>not</em> accessible. * * @see Field * @see Method --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/lang/reflect/DefaultAccessibility.java Tue Oct 13 14:08:57 2009 -0700 @@ -0,0 +1,69 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6648344 + * @summary Test that default accessibility is false + * @author Joseph D. Darcy + */ + +import java.lang.reflect.*; + +public class DefaultAccessibility { + private DefaultAccessibility() { + super(); + } + + private static int f = 42; + + public static void main(String... args) throws Exception { + Class<?> daClass = (new DefaultAccessibility()).getClass(); + + int elementCount = 0; + for(Constructor<?> ctor : daClass.getDeclaredConstructors()) { + elementCount++; + if (ctor.isAccessible()) + throw new RuntimeException("Unexpected accessibility for constructor " + + ctor); + } + + for(Method method : daClass.getDeclaredMethods()) { + elementCount++; + if (method.isAccessible()) + throw new RuntimeException("Unexpected accessibility for method " + + method); + } + + for(Field field : daClass.getDeclaredFields()) { + elementCount++; + if (field.isAccessible()) + throw new RuntimeException("Unexpected accessibility for field " + + field); + } + + if (elementCount < 3) + throw new RuntimeException("Expected at least three members; only found " + + elementCount); + } +}
2009-10-13

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk7/tl/jdk/rev/9d240dbadaa3
2009-10-13

EVALUATION A fine point to clarify.
2008-01-08