mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-09 10:39:25 +00:00
4683761: Incomplete Introspection on nonpublic classes lead to IllegalAccessExceptions
Reviewed-by: alexsch
This commit is contained in:
parent
d7081aaf76
commit
c1409aacef
@ -28,6 +28,7 @@ package java.beans;
|
||||
import com.sun.beans.TypeResolver;
|
||||
import com.sun.beans.WeakCache;
|
||||
import com.sun.beans.finder.ClassFinder;
|
||||
import com.sun.beans.finder.MethodFinder;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
@ -1281,7 +1282,20 @@ public class Introspector {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
Method method = result[i];
|
||||
if (!method.getDeclaringClass().equals(clz)) {
|
||||
result[i] = null;
|
||||
result[i] = null; // ignore methods declared elsewhere
|
||||
}
|
||||
else {
|
||||
try {
|
||||
method = MethodFinder.findAccessibleMethod(method);
|
||||
Class<?> type = method.getDeclaringClass();
|
||||
result[i] = type.equals(clz) || type.isInterface()
|
||||
? method
|
||||
: null; // ignore methods from superclasses
|
||||
}
|
||||
catch (NoSuchMethodException exception) {
|
||||
// commented out because of 6976577
|
||||
// result[i] = null; // ignore inaccessible methods
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredMethodCache.put(clz, result);
|
||||
|
||||
45
jdk/test/java/beans/Introspector/Test4683761.java
Normal file
45
jdk/test/java/beans/Introspector/Test4683761.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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 4683761
|
||||
* @summary Tests that all public methods in a public class
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Test4683761 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("key", "value");
|
||||
Map.Entry<String, String> entry = map.entrySet().iterator().next();
|
||||
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(entry.getClass())) {
|
||||
System.out.println(pd.getName() + " = " + pd.getReadMethod().invoke(entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user