Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
97d0c074
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
97d0c074
编写于
9月 06, 2013
作者:
J
jfranck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
5047859: (reflect) Class.getField can't find String[].length
Reviewed-by: darcy, mchung
上级
b87045da
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
108 addition
and
27 deletion
+108
-27
src/share/classes/java/lang/Class.java
src/share/classes/java/lang/Class.java
+44
-27
test/java/lang/Class/getField/ArrayLength.java
test/java/lang/Class/getField/ArrayLength.java
+64
-0
未找到文件。
src/share/classes/java/lang/Class.java
浏览文件 @
97d0c074
...
...
@@ -1484,22 +1484,24 @@ public final class Class<T> implements java.io.Serializable,
/**
* Returns an array containing {@code Field} objects reflecting all
* the accessible public fields of the class or interface represented by
* this {@code Class} object. The elements in the array returned are
* not sorted and are not in any particular order. This method returns an
* array of length 0 if the class or interface has no accessible public
* fields, or if it represents an array class, a primitive type, or void.
* this {@code Class} object.
*
* <p> Specifically, if this {@code Class} object represents a class,
* this method returns the public fields of this class and of all its
* superclasses. If this {@code Class} object represents an
* interface, this method returns the fields of this interface and of all
* its superinterfaces.
* <p> If this {@code Class} object represents a class or interface with no
* no accessible public fields, then this method returns an array of length
* 0.
*
* <p> If this {@code Class} object represents a class, then this method
* returns the public fields of the class and of all its superclasses.
*
* <p> If this {@code Class} object represents an interface, then this
* method returns the fields of the interface and of all its
* superinterfaces.
*
* <p> The implicit length field for array class is not reflected by this
* method. User code should use the methods of class {@code Array} to
* manipulate arrays.
* <p> If this {@code Class} object represents an array type, a primitive
* type, or void, then this method returns an array of length 0.
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
* <p> The elements in the array returned are not sorted and are not in any
* particular order.
*
* @return the array of {@code Field} objects representing the
* public fields
...
...
@@ -1512,6 +1514,8 @@ public final class Class<T> implements java.io.Serializable,
* of this class.
*
* @since JDK1.1
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public
Field
[]
getFields
()
throws
SecurityException
{
...
...
@@ -1595,13 +1599,14 @@ public final class Class<T> implements java.io.Serializable,
/**
* Returns a {@code Field} object that reflects the specified public
*
member field of the class or interface represented by this
*
{@code Class} object. The {@code name} parameter is a
*
{@code String} specifying the
simple name of the desired field.
* Returns a {@code Field} object that reflects the specified public
member
*
field of the class or interface represented by this {@code Class}
*
object. The {@code name} parameter is a {@code String} specifying the
* simple name of the desired field.
*
* <p> The field to be reflected is determined by the algorithm that
* follows. Let C be the class represented by this object:
* follows. Let C be the class or interface represented by this object:
*
* <OL>
* <LI> If C declares a public field with the name specified, that is the
* field to be reflected.</LI>
...
...
@@ -1614,7 +1619,8 @@ public final class Class<T> implements java.io.Serializable,
* is thrown.</LI>
* </OL>
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
* <p> If this {@code Class} object represents an array type, then this
* method does not find the {@code length} field of the array type.
*
* @param name the field name
* @return the {@code Field} object of this class specified by
...
...
@@ -1631,6 +1637,8 @@ public final class Class<T> implements java.io.Serializable,
* of this class.
*
* @since JDK1.1
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public
Field
getField
(
String
name
)
...
...
@@ -1800,12 +1808,15 @@ public final class Class<T> implements java.io.Serializable,
* declared by the class or interface represented by this
* {@code Class} object. This includes public, protected, default
* (package) access, and private fields, but excludes inherited fields.
* The elements in the array returned are not sorted and are not in any
* particular order. This method returns an array of length 0 if the class
* or interface declares no fields, or if this {@code Class} object
* represents a primitive type, an array class, or void.
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
* <p> If this {@code Class} object represents a class or interface with no
* declared fields, then this method returns an array of length 0.
*
* <p> If this {@code Class} object represents an array type, a primitive
* type, or void, then this method returns an array of length 0.
*
* <p> The elements in the array returned are not sorted and are not in any
* particular order.
*
* @return the array of {@code Field} objects representing all the
* declared fields of this class
...
...
@@ -1831,6 +1842,8 @@ public final class Class<T> implements java.io.Serializable,
* </ul>
*
* @since JDK1.1
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public
Field
[]
getDeclaredFields
()
throws
SecurityException
{
...
...
@@ -1935,9 +1948,11 @@ public final class Class<T> implements java.io.Serializable,
/**
* Returns a {@code Field} object that reflects the specified declared
* field of the class or interface represented by this {@code Class}
* object. The {@code name} parameter is a {@code String} that
* specifies the simple name of the desired field. Note that this method
* will not reflect the {@code length} field of an array class.
* object. The {@code name} parameter is a {@code String} that specifies
* the simple name of the desired field.
*
* <p> If this {@code Class} object represents an array type, then this
* method does not find the {@code length} field of the array type.
*
* @param name the name of the field
* @return the {@code Field} object for the specified field in this
...
...
@@ -1967,6 +1982,8 @@ public final class Class<T> implements java.io.Serializable,
* </ul>
*
* @since JDK1.1
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public
Field
getDeclaredField
(
String
name
)
...
...
test/java/lang/Class/getField/ArrayLength.java
0 → 100644
浏览文件 @
97d0c074
/*
* Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 5047859
* @summary verify that for an array type class instance, getField("length")
* throws an exception, and getFields() does not contain a Field for
* 'length'
*/
import
java.lang.reflect.Field
;
public
class
ArrayLength
{
public
static
void
main
(
String
[]
args
)
{
int
failed
=
0
;
try
{
new
String
[
0
].
getClass
().
getField
(
"length"
);
failed
++;
System
.
out
.
println
(
"getField(\"length\") should throw NoSuchFieldException"
);
}
catch
(
NoSuchFieldException
e
)
{
}
try
{
new
String
[
0
].
getClass
().
getDeclaredField
(
"length"
);
failed
++;
System
.
out
.
println
(
"getDeclaredField(\"length\") should throw NoSuchFieldException"
);
}
catch
(
NoSuchFieldException
e
)
{
}
if
(
new
String
[
0
].
getClass
().
getFields
().
length
!=
0
)
{
failed
++;
System
.
out
.
println
(
"getFields() for an array type should return a zero length array"
);
}
if
(
new
String
[
0
].
getClass
().
getDeclaredFields
().
length
!=
0
)
{
failed
++;
System
.
out
.
println
(
"getDeclaredFields() for an array type should return a zero length array"
);
}
if
(
failed
!=
0
)
throw
new
RuntimeException
(
"Test failed see log for details"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录