undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.JavaBean;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
import javax.swing.SwingContainer;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4058433 8131055
|
||||
* @summary Check if the user-defined bean info
|
||||
* is not overridden with the annotated one.
|
||||
* @author a.stepanov
|
||||
*/
|
||||
|
||||
|
||||
public class TestBeanInfoPriority {
|
||||
|
||||
// ========== test bean (annotations must be ignored!) ==========
|
||||
|
||||
@JavaBean(
|
||||
description = "annotation-description",
|
||||
defaultProperty = "other",
|
||||
defaultEventSet = "mouse")
|
||||
@SwingContainer(value = false)
|
||||
public static class TestClass {
|
||||
|
||||
private int value;
|
||||
private double other;
|
||||
|
||||
@BeanProperty(
|
||||
bound = false,
|
||||
expert = false,
|
||||
hidden = false,
|
||||
preferred = false,
|
||||
required = false,
|
||||
visualUpdate = false,
|
||||
description = "annotation-value",
|
||||
enumerationValues = {
|
||||
"javax.swing.SwingConstants.NORTH"}
|
||||
)
|
||||
public void setValue(int v) { value = v; }
|
||||
public int getValue() { return value; }
|
||||
|
||||
|
||||
@BeanProperty(
|
||||
bound = true,
|
||||
expert = true,
|
||||
hidden = true,
|
||||
preferred = true,
|
||||
required = true,
|
||||
visualUpdate = true,
|
||||
description = "annotation-other",
|
||||
enumerationValues = {
|
||||
"javax.swing.SwingConstants.LEFT",
|
||||
"javax.swing.SwingConstants.RIGHT",
|
||||
"javax.swing.SwingConstants.CENTER"}
|
||||
)
|
||||
public void setOther(double o) { other = o; }
|
||||
public double getOther() { return other; }
|
||||
|
||||
public void addActionListener(ActionListener l) {}
|
||||
public void removeActionListener(ActionListener l) {}
|
||||
|
||||
public void addMouseListener(MouseListener l) {}
|
||||
public void removeMouseListener(MouseListener l) {}
|
||||
}
|
||||
|
||||
// ========== user-defined bean info ==========
|
||||
|
||||
public static class TestClassBeanInfo extends SimpleBeanInfo {
|
||||
|
||||
private static final int iOther = 0;
|
||||
private static final int iValue = 1;
|
||||
|
||||
private static final int iAction = 0;
|
||||
private static final int iMouse = 1;
|
||||
|
||||
|
||||
@Override
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
|
||||
BeanDescriptor bd = new BeanDescriptor(TestClass.class, null);
|
||||
bd.setShortDescription("user-defined-description");
|
||||
bd.setValue("isContainer", true);
|
||||
bd.setValue("containerDelegate", "user-defined-delegate");
|
||||
|
||||
return bd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
|
||||
PropertyDescriptor[] p = new PropertyDescriptor[2];
|
||||
|
||||
try {
|
||||
|
||||
// value
|
||||
PropertyDescriptor pdValue = new PropertyDescriptor(
|
||||
"value", TestClass.class, "getValue", "setValue");
|
||||
pdValue.setBound(true);
|
||||
pdValue.setConstrained(true);
|
||||
pdValue.setExpert(true);
|
||||
pdValue.setHidden(true);
|
||||
pdValue.setPreferred(true);
|
||||
pdValue.setValue("required", true);
|
||||
pdValue.setValue("visualUpdate", true);
|
||||
pdValue.setShortDescription("user-defined-value");
|
||||
pdValue.setValue("enumerationValues", new Object[]{
|
||||
"EAST", 3, "javax.swing.SwingConstants.EAST",
|
||||
"WEST", 7, "javax.swing.SwingConstants.WEST"});
|
||||
p[iValue] = pdValue;
|
||||
|
||||
// other
|
||||
PropertyDescriptor pdOther = new PropertyDescriptor(
|
||||
"other", TestClass.class, "getOther", "setOther");
|
||||
pdOther.setBound(false);
|
||||
pdOther.setConstrained(false);
|
||||
pdOther.setExpert(false);
|
||||
pdOther.setHidden(false);
|
||||
pdOther.setPreferred(false);
|
||||
pdOther.setValue("required", false);
|
||||
pdOther.setValue("visualUpdate", false);
|
||||
pdOther.setShortDescription("user-defined-other");
|
||||
pdOther.setValue("enumerationValues", new Object[]{
|
||||
"TOP", 1, "javax.swing.SwingConstants.TOP"});
|
||||
p[iOther] = pdOther;
|
||||
|
||||
} catch(IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventSetDescriptor[] getEventSetDescriptors() {
|
||||
EventSetDescriptor[] es = new EventSetDescriptor[2];
|
||||
try {
|
||||
es[iAction] = new EventSetDescriptor(
|
||||
TestClass.class,
|
||||
"actionListener",
|
||||
java.awt.event.ActionListener.class,
|
||||
new String[] {"actionPerformed"},
|
||||
"addActionListener",
|
||||
"removeActionListener");
|
||||
es[iMouse] = new EventSetDescriptor(
|
||||
TestClass.class,
|
||||
"mouseListener",
|
||||
java.awt.event.MouseListener.class,
|
||||
new String[] {"mouseClicked", "mousePressed", "mouseReleased", "mouseEntered", "mouseExited"},
|
||||
"addMouseListener",
|
||||
"removeMouseListener");
|
||||
} catch(IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodDescriptor[] getMethodDescriptors() {
|
||||
MethodDescriptor[] m = new MethodDescriptor[0];
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPropertyIndex() { return iValue; } // default: value
|
||||
|
||||
@Override
|
||||
public int getDefaultEventIndex() { return iAction; } // default: action
|
||||
|
||||
@Override
|
||||
public java.awt.Image getIcon(int iconKind) { return null; }
|
||||
}
|
||||
|
||||
// ========== auxiliary functions ==========
|
||||
|
||||
static void checkEq(String what, Object v, Object ref) throws Exception {
|
||||
|
||||
if ((v != null) && v.equals(ref)) {
|
||||
System.out.println(what + ": ok (" + ref.toString() + ")");
|
||||
} else {
|
||||
throw new Exception(
|
||||
"invalid " + what + ", expected: \"" + ref + "\", got: \"" + v + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkEnumEq(String what, Object v, Object ref[]) throws Exception {
|
||||
|
||||
what = "\"" + what + "\"";
|
||||
if (v == null) {
|
||||
throw new Exception("null " + what + " enumeration values");
|
||||
}
|
||||
|
||||
String msg = "invalid " + what + " enumeration values";
|
||||
if (!(v instanceof Object[])) { throw new Exception(msg); }
|
||||
|
||||
if (Arrays.equals((Object []) v, ref)) {
|
||||
System.out.println(what + " enumeration values: ok");
|
||||
} else { throw new Exception(msg); }
|
||||
}
|
||||
|
||||
|
||||
// ========== test ==========
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
BeanInfo i = Introspector.getBeanInfo(TestClass.class, Object.class);
|
||||
BeanDescriptor bd = i.getBeanDescriptor();
|
||||
|
||||
checkEq("description", bd.getShortDescription(), "user-defined-description");
|
||||
checkEq("default property index", i.getDefaultPropertyIndex(), 1);
|
||||
checkEq("default event index", i.getDefaultEventIndex(), 0);
|
||||
|
||||
checkEq("isContainer", i.getBeanDescriptor().getValue("isContainer"), true);
|
||||
checkEq("containerDelegate",
|
||||
i.getBeanDescriptor().getValue("containerDelegate"), "user-defined-delegate");
|
||||
System.out.println("");
|
||||
|
||||
PropertyDescriptor[] pds = i.getPropertyDescriptors();
|
||||
for (PropertyDescriptor pd: pds) {
|
||||
String name = pd.getName();
|
||||
switch (name) {
|
||||
case "value":
|
||||
checkEq("\"value\" isBound", pd.isBound(), true);
|
||||
checkEq("\"value\" isConstrained", pd.isConstrained(), true);
|
||||
checkEq("\"value\" isExpert", pd.isExpert(), true);
|
||||
checkEq("\"value\" isHidden", pd.isHidden(), true);
|
||||
checkEq("\"value\" isPreferred", pd.isPreferred(), true);
|
||||
checkEq("\"value\" required", pd.getValue("required"), true);
|
||||
checkEq("\"value\" visualUpdate", pd.getValue("visualUpdate"), true);
|
||||
|
||||
checkEq("\"value\" description", pd.getShortDescription(), "user-defined-value");
|
||||
|
||||
checkEnumEq(pd.getName(), pd.getValue("enumerationValues"),
|
||||
new Object[]{
|
||||
"EAST", 3, "javax.swing.SwingConstants.EAST",
|
||||
"WEST", 7, "javax.swing.SwingConstants.WEST"});
|
||||
System.out.println("");
|
||||
break;
|
||||
case "other":
|
||||
checkEq("\"other\" isBound", pd.isBound(), false);
|
||||
checkEq("\"other\" isConstrained", pd.isConstrained(), false);
|
||||
checkEq("\"other\" isExpert", pd.isExpert(), false);
|
||||
checkEq("\"other\" isHidden", pd.isHidden(), false);
|
||||
checkEq("\"other\" isPreferred", pd.isPreferred(), false);
|
||||
checkEq("\"other\" required", pd.getValue("required"), false);
|
||||
checkEq("\"other\" visualUpdate", pd.getValue("visualUpdate"), false);
|
||||
|
||||
checkEq("\"other\" description", pd.getShortDescription(), "user-defined-other");
|
||||
|
||||
checkEnumEq(pd.getName(), pd.getValue("enumerationValues"),
|
||||
new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
|
||||
System.out.println("");
|
||||
break;
|
||||
default:
|
||||
throw new Exception("invalid property descriptor: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
317
test/jdk/java/beans/Introspector/4058433/TestBeanProperty.java
Normal file
317
test/jdk/java/beans/Introspector/4058433/TestBeanProperty.java
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2015, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4058433
|
||||
* @summary Tests the BeanProperty annotation
|
||||
* @author Sergey Malenkov
|
||||
* @library ..
|
||||
*/
|
||||
public class TestBeanProperty {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class<?>[] types =
|
||||
{B.class, BL.class, BLF.class, E.class, H.class, P.class,
|
||||
VU.class, D.class, EVD.class, EVE.class, EV.class, EVL.class,
|
||||
EVX.class, R.class};
|
||||
for (Class<?> type : types) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
|
||||
if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("not bound");
|
||||
}
|
||||
if ((BL.class == type) == !pd.isBound()) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("bound");
|
||||
}
|
||||
if ((E.class == type) == !pd.isExpert()) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("expert");
|
||||
}
|
||||
if ((H.class == type) == !pd.isHidden()) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("hidden");
|
||||
}
|
||||
if ((P.class == type) == !pd.isPreferred()) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("preferred");
|
||||
}
|
||||
if ((R.class == type) == !Boolean.TRUE.equals(pd.getValue("required"))) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("required");
|
||||
}
|
||||
if ((D.class == type) == !"getter".equals(pd.getShortDescription())) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("shortDescription");
|
||||
}
|
||||
if ((VU.class == type) == !Boolean.TRUE.equals(pd.getValue("visualUpdate"))) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("visualUpdate");
|
||||
}
|
||||
if ((EV.class == type) == !isEV(pd, "LEFT", 2, "javax.swing.SwingConstants.LEFT", "RIGHT", 4, "javax.swing.SwingConstants.RIGHT")) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("enumerationValues from another package");
|
||||
}
|
||||
if ((EVL.class == type) == !isEV(pd, "ZERO", 0, "ZERO", "ONE", 1, "ONE")) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("enumerationValues from another package");
|
||||
}
|
||||
if ((EVX.class == type) == !isEV(pd, "ZERO", 0, "X.ZERO", "ONE", 1, "X.ONE")) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("enumerationValues from another package");
|
||||
}
|
||||
if (EVD.class == type && !isEV(pd)) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("EV:"+ pd.getValue("enumerationValues"));
|
||||
}
|
||||
if (EVE.class == type && !isEV(pd)) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error("EV:"+ pd.getValue("enumerationValues"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEV(PropertyDescriptor pd, Object... expected) {
|
||||
Object value = pd.getValue("enumerationValues");
|
||||
return value instanceof Object[] && Arrays.equals((Object[]) value, expected);
|
||||
}
|
||||
|
||||
public static class B {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BL {
|
||||
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
this.pcs.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
this.pcs.removePropertyChangeListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BLF {
|
||||
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
this.pcs.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
this.pcs.removePropertyChangeListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public static class E {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(expert = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class H {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(hidden = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class P {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(preferred = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class R {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(required = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VU {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(visualUpdate = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class D {
|
||||
private int value;
|
||||
|
||||
@BeanProperty(description = "getter")
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(description = "setter")
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EVD {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty()
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EVE {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(enumerationValues = {})
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EV {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(enumerationValues = {
|
||||
"javax.swing.SwingConstants.LEFT",
|
||||
"javax.swing.SwingConstants.RIGHT"})
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EVL {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(enumerationValues = {"ZERO", "ONE"})
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static int ZERO = 0;
|
||||
public static int ONE = 1;
|
||||
}
|
||||
|
||||
public static class EVX {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@BeanProperty(enumerationValues = {
|
||||
"X.ZERO",
|
||||
"X.ONE"})
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface X {
|
||||
int ZERO = 0;
|
||||
int ONE = 1;
|
||||
}
|
||||
}
|
||||
174
test/jdk/java/beans/Introspector/4058433/TestJavaBean.java
Normal file
174
test/jdk/java/beans/Introspector/4058433/TestJavaBean.java
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2015, 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.
|
||||
*/
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.JavaBean;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4058433
|
||||
* @summary Tests the JavaBean annotation
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
public class TestJavaBean {
|
||||
|
||||
static final String DSCR = "description";
|
||||
static final String PRP = "value";
|
||||
static final String ACT = "action";
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
test(X.class, "TestJavaBean$X", "TestJavaBean$X", null, null);
|
||||
test(D.class, "TestJavaBean$D", DSCR, null, null);
|
||||
test(DP.class, "TestJavaBean$DP", "TestJavaBean$DP", PRP, null);
|
||||
test(DES.class, "TestJavaBean$DES", "TestJavaBean$DES", null, ACT);
|
||||
test(DDP.class, "TestJavaBean$DDP", DSCR, PRP, null);
|
||||
test(DDES.class, "TestJavaBean$DDES", DSCR, null, ACT);
|
||||
test(DPDES.class, "TestJavaBean$DPDES", "TestJavaBean$DPDES", PRP, ACT);
|
||||
test(DDPDES.class, "TestJavaBean$DDPDES", DSCR, PRP, ACT);
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, String name, String descr,
|
||||
String prop, String event) throws Exception {
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
BeanDescriptor bd = info.getBeanDescriptor();
|
||||
|
||||
if (!bd.getName().equals(name)) {
|
||||
throw new Error("unexpected name of the bean");
|
||||
}
|
||||
|
||||
if (!bd.getShortDescription().equals(descr)) {
|
||||
throw new Error("unexpected description of the bean");
|
||||
}
|
||||
|
||||
int dp = info.getDefaultPropertyIndex();
|
||||
if (dp < 0 && prop != null) {
|
||||
throw new Error("unexpected index of the default property");
|
||||
}
|
||||
if (dp >= 0) {
|
||||
if (!info.getPropertyDescriptors()[dp].getName().equals(prop)) {
|
||||
throw new Error("unexpected default property");
|
||||
}
|
||||
}
|
||||
int des = info.getDefaultEventIndex();
|
||||
if (des < 0 && event != null) {
|
||||
throw new Error("unexpected index of the default event set");
|
||||
}
|
||||
if (des >= 0) {
|
||||
if (!info.getEventSetDescriptors()[des].getName().equals(event)) {
|
||||
throw new Error("unexpected default event set");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class X {
|
||||
}
|
||||
|
||||
@JavaBean(description = DSCR)
|
||||
public static class D {
|
||||
}
|
||||
|
||||
@JavaBean(defaultProperty = PRP)
|
||||
public static class DP {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@JavaBean(defaultEventSet = ACT)
|
||||
public static class DES {
|
||||
public void addActionListener(ActionListener listener) {
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
@JavaBean(description = DSCR, defaultProperty = PRP)
|
||||
public static class DDP {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@JavaBean(description = DSCR, defaultEventSet = ACT)
|
||||
public static class DDES {
|
||||
public void addActionListener(ActionListener listener) {
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
@JavaBean(defaultProperty = PRP, defaultEventSet = ACT)
|
||||
public static class DPDES {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addActionListener(ActionListener listener) {
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
@JavaBean(description = DSCR, defaultProperty = PRP, defaultEventSet = ACT)
|
||||
public static class DDPDES {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addActionListener(ActionListener listener) {
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
}
|
||||
}
|
||||
}
|
||||
100
test/jdk/java/beans/Introspector/4058433/TestSwingContainer.java
Normal file
100
test/jdk/java/beans/Introspector/4058433/TestSwingContainer.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2015, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.util.Objects;
|
||||
import javax.swing.SwingContainer;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4058433
|
||||
* @summary Tests the SwingContainer annotation
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
public class TestSwingContainer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(X.class, null, null);
|
||||
test(H.class, true, "");
|
||||
test(G.class, true, "");
|
||||
test(F.class, true, "method");
|
||||
test(E.class, false, "");
|
||||
test(D.class, false, "");
|
||||
test(C.class, true, "");
|
||||
test(B.class, false, "method");
|
||||
test(A.class, true, "method");
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, Object iC, Object cD) throws Exception {
|
||||
System.out.println(type);
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
BeanDescriptor bd = info.getBeanDescriptor();
|
||||
test(bd, "isContainer", iC);
|
||||
test(bd, "containerDelegate", cD);
|
||||
}
|
||||
|
||||
private static void test(BeanDescriptor bd, String name, Object expected) {
|
||||
Object value = bd.getValue(name);
|
||||
System.out.println("\t" + name + " = " + value);
|
||||
if (!Objects.equals(value, expected)) {
|
||||
throw new Error(name + ": expected = " + expected + "; actual = " + value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class X {
|
||||
}
|
||||
|
||||
@SwingContainer()
|
||||
public static class H {
|
||||
}
|
||||
|
||||
@SwingContainer(delegate = "")
|
||||
public static class G {
|
||||
}
|
||||
|
||||
@SwingContainer(delegate = "method")
|
||||
public static class F {
|
||||
}
|
||||
|
||||
@SwingContainer(false)
|
||||
public static class E {
|
||||
}
|
||||
|
||||
@SwingContainer(value = false, delegate = "")
|
||||
public static class D {
|
||||
}
|
||||
|
||||
@SwingContainer(value = true, delegate = "")
|
||||
public static class C {
|
||||
}
|
||||
|
||||
@SwingContainer(value = false, delegate = "method")
|
||||
public static class B {
|
||||
}
|
||||
|
||||
@SwingContainer(value = true, delegate = "method")
|
||||
public static class A {
|
||||
}
|
||||
}
|
||||
58
test/jdk/java/beans/Introspector/4168475/Test4168475.java
Normal file
58
test/jdk/java/beans/Introspector/4168475/Test4168475.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2007, 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 4168475
|
||||
* @summary Tests that you can override BeanInfo for core classes
|
||||
* @author Graham Hamilton
|
||||
*/
|
||||
|
||||
import infos.ComponentBeanInfo;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test4168475 {
|
||||
private static final Class CLASS = ComponentBeanInfo.class;
|
||||
private static final String[] PATH = {"infos"};
|
||||
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
Introspector.setBeanInfoSearchPath(PATH);
|
||||
BeanInfo info = Introspector.getBeanInfo(Component.class);
|
||||
PropertyDescriptor[] pds = info.getPropertyDescriptors();
|
||||
|
||||
// The custom ComponentBeanInfo we deliver
|
||||
// only provides a single property.
|
||||
|
||||
if (pds.length != 1) {
|
||||
throw new Error("wrong number of properties");
|
||||
}
|
||||
if (!pds[0].getName().equals("name")) {
|
||||
throw new Error("unexpected property name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2007, 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.
|
||||
*/
|
||||
|
||||
package infos;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class ComponentBeanInfo extends SimpleBeanInfo {
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
return new PropertyDescriptor[] {
|
||||
new PropertyDescriptor("name", Component.class)
|
||||
};
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
test/jdk/java/beans/Introspector/4520754/Foo.java
Normal file
45
test/jdk/java/beans/Introspector/4520754/Foo.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
// The foo bean is it's own beaninfo
|
||||
public class Foo extends SimpleBeanInfo {
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
BeanDescriptor bd = new BeanDescriptor(Foo.class);
|
||||
// set a value to ensure that it's unique
|
||||
bd.setValue("test", Boolean.TRUE);
|
||||
return bd;
|
||||
}
|
||||
|
||||
private int x;
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
34
test/jdk/java/beans/Introspector/4520754/FooBar.java
Normal file
34
test/jdk/java/beans/Introspector/4520754/FooBar.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
public class FooBar extends Foo {
|
||||
private int y;
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
34
test/jdk/java/beans/Introspector/4520754/FooBarBeanInfo.java
Normal file
34
test/jdk/java/beans/Introspector/4520754/FooBarBeanInfo.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class FooBarBeanInfo extends SimpleBeanInfo {
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
BeanDescriptor bd = new BeanDescriptor(FooBar.class);
|
||||
// set a value to ensure that it's unique
|
||||
bd.setValue("test", Boolean.TRUE);
|
||||
return bd;
|
||||
}
|
||||
}
|
||||
115
test/jdk/java/beans/Introspector/4520754/Test4520754.java
Normal file
115
test/jdk/java/beans/Introspector/4520754/Test4520754.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2025, 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 4168475 4520754
|
||||
* @summary Tests for the removal of some of the exception based control flow
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import infos.ComponentBeanInfo;
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.List;
|
||||
import java.awt.Menu;
|
||||
import java.awt.Panel;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
public class Test4520754 {
|
||||
/**
|
||||
* This is here to force the BeanInfo classes to be compiled
|
||||
*/
|
||||
private static final Class[] COMPILE = {
|
||||
ComponentBeanInfo.class,
|
||||
FooBarBeanInfo.class,
|
||||
WombatBeanInfo.class,
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
// ensure that 4168475 does not regress
|
||||
test4168475(Component.class);
|
||||
// AWT classes (com.sun.beans.infos.ComponentBeanInfo)
|
||||
test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
|
||||
// Swing classes (dt.jar)
|
||||
test(null, JButton.class, JCheckBox.class);
|
||||
// user defined classes
|
||||
test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
|
||||
}
|
||||
|
||||
private static void test(Boolean mark, Class... types) {
|
||||
for (Class type : types) {
|
||||
BeanInfo info = getBeanInfo(mark, type);
|
||||
if (info == null) {
|
||||
throw new Error("could not find BeanInfo for " + type);
|
||||
}
|
||||
if (mark != info.getBeanDescriptor().getValue("test")) {
|
||||
throw new Error("could not find marked BeanInfo for " + type);
|
||||
}
|
||||
}
|
||||
Introspector.flushCaches();
|
||||
}
|
||||
|
||||
private static BeanInfo getBeanInfo(Boolean mark, Class type) {
|
||||
System.out.println("test=" + mark + " for " + type);
|
||||
BeanInfo info;
|
||||
try {
|
||||
info = Introspector.getBeanInfo(type);
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
if (info == null) {
|
||||
throw new Error("could not find BeanInfo for " + type);
|
||||
}
|
||||
if (mark != info.getBeanDescriptor().getValue("test")) {
|
||||
throw new Error("could not find marked BeanInfo for " + type);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a regression test to ensure that 4168475 does not regress.
|
||||
*/
|
||||
private static void test4168475(Class type) {
|
||||
String[] newPath = {"infos"};
|
||||
String[] oldPath = Introspector.getBeanInfoSearchPath();
|
||||
|
||||
Introspector.setBeanInfoSearchPath(newPath);
|
||||
BeanInfo info = getBeanInfo(Boolean.TRUE, type);
|
||||
Introspector.setBeanInfoSearchPath(oldPath);
|
||||
|
||||
PropertyDescriptor[] pds = info.getPropertyDescriptors();
|
||||
if (pds.length != 1) {
|
||||
throw new Error("could not find custom BeanInfo for " + type);
|
||||
}
|
||||
Introspector.flushCaches();
|
||||
}
|
||||
}
|
||||
34
test/jdk/java/beans/Introspector/4520754/Wombat.java
Normal file
34
test/jdk/java/beans/Introspector/4520754/Wombat.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
public class Wombat {
|
||||
private int x;
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
34
test/jdk/java/beans/Introspector/4520754/WombatBeanInfo.java
Normal file
34
test/jdk/java/beans/Introspector/4520754/WombatBeanInfo.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class WombatBeanInfo extends SimpleBeanInfo {
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
BeanDescriptor bd = new BeanDescriptor(Wombat.class);
|
||||
// set a value to ensure that it's unique
|
||||
bd.setValue("test", Boolean.TRUE);
|
||||
return bd;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
package infos;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class ComponentBeanInfo extends SimpleBeanInfo {
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
BeanDescriptor bd = new BeanDescriptor(Component.class);
|
||||
// set a value to ensure that it's unique
|
||||
bd.setValue("test", Boolean.TRUE);
|
||||
return bd;
|
||||
}
|
||||
|
||||
// Only an array of 1 Property Descriptor
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
return new PropertyDescriptor[] {
|
||||
new PropertyDescriptor("name", Component.class)
|
||||
};
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
test/jdk/java/beans/Introspector/4750368/Test4750368.java
Normal file
56
test/jdk/java/beans/Introspector/4750368/Test4750368.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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 4750368
|
||||
* @summary Tests for class name collision in Introspector
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.List;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test4750368 {
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
if (getLength(com.foo.test.Component.class) == getLength(Component.class)) {
|
||||
throw new Error("test failed for Component");
|
||||
}
|
||||
if (getLength(java.util.List.class) == getLength(List.class)) {
|
||||
throw new Error("test failed for List");
|
||||
}
|
||||
}
|
||||
|
||||
private static int getLength(Class type) throws IntrospectionException {
|
||||
PropertyDescriptor[] pds = Introspector.getBeanInfo(type).getPropertyDescriptors();
|
||||
System.out.println(type + ": " + pds.length);
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
System.out.println(" - " + pd.getName());
|
||||
}
|
||||
return pds.length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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.
|
||||
*/
|
||||
|
||||
package com.foo.test;
|
||||
|
||||
public class Component {
|
||||
private String name;
|
||||
private int value;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
96
test/jdk/java/beans/Introspector/6380849/TestBeanInfo.java
Normal file
96
test/jdk/java/beans/Introspector/6380849/TestBeanInfo.java
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 6380849
|
||||
* @summary Tests BeanInfo finder
|
||||
* @modules java.desktop/java.beans:open
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import beans.FirstBean;
|
||||
import beans.FirstBeanBeanInfo;
|
||||
import beans.SecondBean;
|
||||
import beans.ThirdBean;
|
||||
|
||||
import infos.SecondBeanBeanInfo;
|
||||
import infos.ThirdBeanBeanInfo;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class TestBeanInfo implements Runnable {
|
||||
|
||||
private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
TestBeanInfo test = new TestBeanInfo();
|
||||
test.run();
|
||||
// the following tests fails on previous build
|
||||
ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name
|
||||
Thread thread = new Thread(group, test);
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, Class<? extends BeanInfo> expected) {
|
||||
BeanInfo actual;
|
||||
try {
|
||||
actual = Introspector.getBeanInfo(type);
|
||||
type = actual.getClass();
|
||||
Method method = type.getDeclaredMethod("getTargetBeanInfo"); // NON-NLS: method name
|
||||
method.setAccessible(true);
|
||||
actual = (BeanInfo) method.invoke(actual);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
if ((actual == null) && (expected != null)) {
|
||||
throw new Error("expected info is not found");
|
||||
}
|
||||
if ((actual != null) && !actual.getClass().equals(expected)) {
|
||||
throw new Error("found unexpected info");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean passed;
|
||||
|
||||
public void run() {
|
||||
Introspector.flushCaches();
|
||||
|
||||
test(FirstBean.class, FirstBeanBeanInfo.class);
|
||||
test(SecondBean.class, null);
|
||||
test(ThirdBean.class, null);
|
||||
test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
|
||||
|
||||
Introspector.setBeanInfoSearchPath(SEARCH_PATH);
|
||||
Introspector.flushCaches();
|
||||
|
||||
test(FirstBean.class, FirstBeanBeanInfo.class);
|
||||
test(SecondBean.class, SecondBeanBeanInfo.class);
|
||||
test(ThirdBean.class, null);
|
||||
test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package beans;
|
||||
|
||||
public class FirstBean {
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package beans;
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class FirstBeanBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
return new BeanDescriptor(FirstBean.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package beans;
|
||||
|
||||
public class SecondBean {
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package beans;
|
||||
|
||||
public class ThirdBean {
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package infos;
|
||||
|
||||
import beans.SecondBean;
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class SecondBeanBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
return new BeanDescriptor(SecondBean.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
package infos;
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class ThirdBeanBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
return new BeanDescriptor(ThirdBeanBeanInfo.class);
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/beans/Introspector/6976577/Test6976577.java
Normal file
71
test/jdk/java/beans/Introspector/6976577/Test6976577.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 6976577
|
||||
* @summary Tests public methods in non-public beans
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import test.Accessor;
|
||||
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Test6976577 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class<?> bt = Accessor.getBeanType();
|
||||
Class<?> lt = Accessor.getListenerType();
|
||||
|
||||
// test PropertyDescriptor
|
||||
PropertyDescriptor pd = new PropertyDescriptor("boolean", bt);
|
||||
test(pd.getReadMethod());
|
||||
test(pd.getWriteMethod());
|
||||
|
||||
// test IndexedPropertyDescriptor
|
||||
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor("indexed", bt);
|
||||
test(ipd.getReadMethod());
|
||||
test(ipd.getWriteMethod());
|
||||
test(ipd.getIndexedReadMethod());
|
||||
test(ipd.getIndexedWriteMethod());
|
||||
|
||||
// test EventSetDescriptor
|
||||
EventSetDescriptor esd = new EventSetDescriptor(bt, "test", lt, "process");
|
||||
test(esd.getAddListenerMethod());
|
||||
test(esd.getRemoveListenerMethod());
|
||||
test(esd.getGetListenerMethod());
|
||||
test(esd.getListenerMethods());
|
||||
}
|
||||
|
||||
private static void test(Method... methods) {
|
||||
for (Method method : methods) {
|
||||
if (method == null) {
|
||||
throw new Error("public method is not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
test/jdk/java/beans/Introspector/6976577/test/Accessor.java
Normal file
104
test/jdk/java/beans/Introspector/6976577/test/Accessor.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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.
|
||||
*/
|
||||
|
||||
package test;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.util.EventListener;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
public class Accessor {
|
||||
|
||||
public static Class<?> getBeanType() {
|
||||
return Bean.class;
|
||||
}
|
||||
|
||||
public static Class<?> getListenerType() {
|
||||
return TestListener.class;
|
||||
}
|
||||
}
|
||||
|
||||
interface TestEvent {
|
||||
}
|
||||
|
||||
interface TestListener extends EventListener {
|
||||
void process(TestEvent event);
|
||||
}
|
||||
|
||||
class Bean {
|
||||
|
||||
private boolean b;
|
||||
private int[] indexed;
|
||||
private TestListener listener;
|
||||
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
this.pcs.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addTestListener(TestListener listener) throws TooManyListenersException {
|
||||
if (listener != null) {
|
||||
if (this.listener != null) {
|
||||
throw new TooManyListenersException();
|
||||
}
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTestListener(TestListener listener) {
|
||||
if (this.listener == listener) {
|
||||
this.listener = null;
|
||||
}
|
||||
}
|
||||
|
||||
public TestListener[] getTestListeners() {
|
||||
return (this.listener != null)
|
||||
? new TestListener[] { this.listener }
|
||||
: new TestListener[0];
|
||||
}
|
||||
|
||||
public boolean isBoolean() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public void setBoolean(boolean b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int[] getIndexed() {
|
||||
return this.indexed;
|
||||
}
|
||||
|
||||
public void setIndexed(int[] values) {
|
||||
this.indexed = values;
|
||||
}
|
||||
|
||||
public int getIndexed(int index) {
|
||||
return this.indexed[index];
|
||||
}
|
||||
|
||||
public void setIndexed(int index, int value) {
|
||||
this.indexed[index] = value;
|
||||
}
|
||||
}
|
||||
76
test/jdk/java/beans/Introspector/7064279/Test7064279.java
Normal file
76
test/jdk/java/beans/Introspector/7064279/Test7064279.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 7064279
|
||||
* @summary Tests that Introspector does not have strong references to context class loader
|
||||
* @author Sergey Malenkov
|
||||
* @run main/othervm -Xmx128m Test7064279
|
||||
*/
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class Test7064279 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
WeakReference ref = new WeakReference(test("test.jar", "test.Test"));
|
||||
try {
|
||||
int[] array = new int[1024];
|
||||
while (true) {
|
||||
array = new int[array.length << 1];
|
||||
}
|
||||
}
|
||||
catch (OutOfMemoryError error) {
|
||||
System.gc();
|
||||
}
|
||||
if (null != ref.get()) {
|
||||
throw new Error("ClassLoader is not released");
|
||||
}
|
||||
}
|
||||
|
||||
private static Object test(String jarName, String className) throws Exception {
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("file:");
|
||||
sb.append(System.getProperty("test.src", "."));
|
||||
sb.append(File.separatorChar);
|
||||
sb.append(jarName);
|
||||
|
||||
ClassLoader newLoader = new URLClassLoader(new URL[] { new URL(sb.toString()) });
|
||||
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
Thread.currentThread().setContextClassLoader(newLoader);
|
||||
test(newLoader.loadClass(className));
|
||||
Thread.currentThread().setContextClassLoader(oldLoader);
|
||||
|
||||
return newLoader;
|
||||
}
|
||||
|
||||
private static void test(Class type) throws Exception {
|
||||
Introspector.getBeanInfo(type);
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/beans/Introspector/7064279/test.jar
Normal file
BIN
test/jdk/java/beans/Introspector/7064279/test.jar
Normal file
Binary file not shown.
51
test/jdk/java/beans/Introspector/7084904/Test7084904.java
Normal file
51
test/jdk/java/beans/Introspector/7084904/Test7084904.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2024, 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.
|
||||
*/
|
||||
import bean.Derived;
|
||||
import java.lang.reflect.Method;
|
||||
/*
|
||||
* @test
|
||||
* @bug 7084904
|
||||
* @summary Compares reflection and bean introspection
|
||||
* @library ..
|
||||
* @run main Test7084904
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
public class Test7084904 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Derived bean = new Derived();
|
||||
Class<?> type = bean.getClass();
|
||||
Method method1 = test("reflection", bean, type.getMethod("isAllowed"));
|
||||
Method method2 = test("bean introspection", bean, BeanUtils.getPropertyDescriptor(type, "allowed").getReadMethod());
|
||||
if (!method1.equals(method2)) {
|
||||
throw new Error("first method is not equal to the second one");
|
||||
}
|
||||
}
|
||||
|
||||
private static Method test(String name, Object bean, Method method) throws Exception {
|
||||
System.out.println("\n === use " + name + " ===");
|
||||
System.out.println(method);
|
||||
System.out.println("declaring " + method.getDeclaringClass());
|
||||
System.out.println("invocation result: " + method.invoke(bean));
|
||||
return method;
|
||||
}
|
||||
}
|
||||
29
test/jdk/java/beans/Introspector/7084904/bean/Base.java
Normal file
29
test/jdk/java/beans/Introspector/7084904/bean/Base.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package bean;
|
||||
|
||||
class Base {
|
||||
public boolean isAllowed() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
26
test/jdk/java/beans/Introspector/7084904/bean/Derived.java
Normal file
26
test/jdk/java/beans/Introspector/7084904/bean/Derived.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
package bean;
|
||||
|
||||
public class Derived extends Base {
|
||||
}
|
||||
45
test/jdk/java/beans/Introspector/7122138/Test7122138.java
Normal file
45
test/jdk/java/beans/Introspector/7122138/Test7122138.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 7122138
|
||||
* @summary Tests generic methods reflection
|
||||
* @author Sergey Malenkov
|
||||
* @library ..
|
||||
*/
|
||||
|
||||
import pack.Sub;
|
||||
|
||||
public class Test7122138 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class<Sub> type = Sub.class;
|
||||
Sub object = type.newInstance();
|
||||
String name = "name";
|
||||
BeanUtils.getPropertyDescriptor(type, name).getWriteMethod().invoke(object, name);
|
||||
if (!name.equals(object.getName())) {
|
||||
throw new Error("name is not set");
|
||||
}
|
||||
}
|
||||
}
|
||||
27
test/jdk/java/beans/Introspector/7122138/pack/Sub.java
Normal file
27
test/jdk/java/beans/Introspector/7122138/pack/Sub.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
|
||||
package pack;
|
||||
|
||||
public class Sub<String> extends Super {
|
||||
}
|
||||
37
test/jdk/java/beans/Introspector/7122138/pack/Super.java
Normal file
37
test/jdk/java/beans/Introspector/7122138/pack/Super.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
|
||||
package pack;
|
||||
|
||||
class Super<T> {
|
||||
|
||||
T name;
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,384 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8130937 8131347
|
||||
* @summary Tests the booleans properties of the BeanProperty annotation
|
||||
* @library ..
|
||||
*/
|
||||
public final class TestBooleanBeanProperties {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
test(Empty.class, false, false, false, false, false, false);
|
||||
test(BoundTrue.class, false, false, false, false, false, false);
|
||||
test(BoundFalse.class, false, false, false, false, false, false);
|
||||
test(BoundListener.class, true, false, false, false, false, false);
|
||||
test(BoundFalseListener.class, false, false, false, false, false, false);
|
||||
test(BoundTrueListener.class, true, false, false, false, false, false);
|
||||
test(ExpertTrue.class, false, true, false, false, false, false);
|
||||
test(ExpertFalse.class, false, false, false, false, false, false);
|
||||
test(HiddenTrue.class, false, false, true, false, false, false);
|
||||
test(HiddenFalse.class, false, false, false, false, false, false);
|
||||
test(PreferredTrue.class, false, false, false, true, false, false);
|
||||
test(PreferredFalse.class, false, false, false, false, false, false);
|
||||
test(RequiredTrue.class, false, false, false, false, true, false);
|
||||
test(RequiredFalse.class, false, false, false, false, false, false);
|
||||
test(VisualUpdateTrue.class, false, false, false, false, false, true);
|
||||
test(VisualUpdateFalse.class, false, false, false, false, false, false);
|
||||
test(All.class, true, true, true, true, true, true);
|
||||
}
|
||||
|
||||
private static void test(Class<?> cls, boolean isBound, boolean isExpert,
|
||||
boolean isHidden, boolean isPref, boolean isReq,
|
||||
boolean isVS) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(cls, "value");
|
||||
if (pd.isBound() != isBound) {
|
||||
throw new RuntimeException("isBound should be: " + isBound);
|
||||
}
|
||||
if (pd.isExpert() != isExpert || getValue(pd, "expert") != isExpert) {
|
||||
throw new RuntimeException("isExpert should be:" + isExpert);
|
||||
}
|
||||
if (pd.isHidden() != isHidden || getValue(pd, "hidden") != isHidden) {
|
||||
throw new RuntimeException("isHidden should be: " + isHidden);
|
||||
}
|
||||
if (pd.isPreferred() != isPref) {
|
||||
throw new RuntimeException("isPreferred should be: " + isPref);
|
||||
}
|
||||
if (getValue(pd, "required") != isReq) {
|
||||
throw new RuntimeException("required should be: " + isReq);
|
||||
}
|
||||
if (getValue(pd, "visualUpdate") != isVS) {
|
||||
throw new RuntimeException("required should be: " + isVS);
|
||||
}
|
||||
if (pd.getValue("enumerationValues") == null) {
|
||||
throw new RuntimeException("enumerationValues should be empty array");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getValue(PropertyDescriptor pd, String value) {
|
||||
return (boolean) pd.getValue(value);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class Empty {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class All {
|
||||
|
||||
private int value;
|
||||
|
||||
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = true, expert = true, hidden = true,
|
||||
preferred = true, required = true, visualUpdate = true,
|
||||
enumerationValues = {})
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// bound property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class BoundTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BoundFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BoundListener {
|
||||
|
||||
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BoundFalseListener {
|
||||
|
||||
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BoundTrueListener {
|
||||
|
||||
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(bound = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// expert property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class ExpertTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(expert = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ExpertFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(expert = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// hidden property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class HiddenTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(hidden = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class HiddenFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(hidden = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// preferred property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class PreferredTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(preferred = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PreferredFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(preferred = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// required property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class RequiredTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(required = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RequiredFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(required = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// visualUpdate property
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class VisualUpdateTrue {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(visualUpdate = true)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class VisualUpdateFalse {
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@BeanProperty(visualUpdate = false)
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
test/jdk/java/beans/Introspector/8132566/CBase.java
Normal file
47
test/jdk/java/beans/Introspector/8132566/CBase.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
|
||||
public class CBase {
|
||||
|
||||
private int value;
|
||||
|
||||
@BeanProperty(
|
||||
bound = true,
|
||||
expert = true,
|
||||
hidden = true,
|
||||
preferred = true,
|
||||
required = true,
|
||||
visualUpdate = true,
|
||||
description = "BASE",
|
||||
enumerationValues = {"javax.swing.SwingConstants.TOP"}
|
||||
)
|
||||
public void setValue(int v) { value = v; }
|
||||
public int getValue() { return value; }
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {}
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {}
|
||||
}
|
||||
42
test/jdk/java/beans/Introspector/8132566/Checker.java
Normal file
42
test/jdk/java/beans/Introspector/8132566/Checker.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Checker {
|
||||
|
||||
static void checkEq(String what, Object v, Object ref) throws Exception {
|
||||
if ((v != null) && v.equals(ref)) {
|
||||
System.out.println(what + ": ok (" + ref.toString() + ")");
|
||||
} else { throw new Exception(
|
||||
"invalid " + what + ", expected: \"" + ref + "\", got: \"" + v + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkEnumEq(String what, Object v, Object ref[]) throws Exception {
|
||||
if (v == null) { throw new Exception("null " + what); }
|
||||
if (!(v instanceof Object[])) { throw new Exception("invalid " + what); }
|
||||
if (Arrays.equals((Object []) v, ref)) { System.out.println(what + ": ok"); }
|
||||
else { throw new Exception("invalid " + what); }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8132566 8131939
|
||||
* @summary Check if the derived class inherits the property info
|
||||
* from the base class.
|
||||
* @author a.stepanov
|
||||
*/
|
||||
|
||||
public class InheritPropertyInfoTest {
|
||||
|
||||
public static class C extends CBase {}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
|
||||
PropertyDescriptor[] pds = i.getPropertyDescriptors();
|
||||
|
||||
Checker.checkEq("number of properties", pds.length, 1);
|
||||
PropertyDescriptor p = pds[0];
|
||||
|
||||
Checker.checkEq("property description", p.getShortDescription(), "BASE");
|
||||
|
||||
Checker.checkEq("isBound", p.isBound(), true);
|
||||
Checker.checkEq("isExpert", p.isExpert(), true);
|
||||
Checker.checkEq("isHidden", p.isHidden(), true);
|
||||
Checker.checkEq("isPreferred", p.isPreferred(), true);
|
||||
Checker.checkEq("required", p.getValue("required"), true);
|
||||
Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), true);
|
||||
|
||||
Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),
|
||||
new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8132566 8132565 8131939
|
||||
* @summary Check if the derived class overrides
|
||||
* the parent's property info.
|
||||
* @author a.stepanov
|
||||
*/
|
||||
|
||||
public class OverridePropertyInfoTest {
|
||||
|
||||
public static class C extends CBase {
|
||||
|
||||
private int value;
|
||||
|
||||
@BeanProperty(
|
||||
bound = false,
|
||||
expert = false,
|
||||
hidden = false,
|
||||
preferred = false,
|
||||
required = false,
|
||||
visualUpdate = false,
|
||||
description = "CHILD",
|
||||
enumerationValues = {"javax.swing.SwingConstants.BOTTOM"}
|
||||
)
|
||||
@Override
|
||||
public void setValue(int v) { value = v; }
|
||||
@Override
|
||||
public int getValue() { return value; }
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {}
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
|
||||
PropertyDescriptor[] pds = i.getPropertyDescriptors();
|
||||
|
||||
Checker.checkEq("number of properties", pds.length, 1);
|
||||
PropertyDescriptor p = pds[0];
|
||||
Checker.checkEq("property description", p.getShortDescription(), "CHILD");
|
||||
|
||||
Checker.checkEq("isBound", p.isBound(), false);
|
||||
Checker.checkEq("isExpert", p.isExpert(), false);
|
||||
Checker.checkEq("isHidden", p.isHidden(), false);
|
||||
Checker.checkEq("isPreferred", p.isPreferred(), false);
|
||||
Checker.checkEq("required", p.getValue("required"), false);
|
||||
Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), false);
|
||||
|
||||
Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),
|
||||
new Object[]{"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2024, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.BeanProperty;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.JavaBean;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8132566 8132669 8131939
|
||||
* @summary Check if the derived class overrides
|
||||
* the parent's user-defined property info.
|
||||
* @author a.stepanov
|
||||
*/
|
||||
|
||||
public class OverrideUserDefPropertyInfoTest {
|
||||
|
||||
private static final boolean baseFlag = true;
|
||||
private static final boolean childFlag = false;
|
||||
|
||||
@JavaBean(description = "CHILD")
|
||||
public static class C extends Base {
|
||||
|
||||
private int x;
|
||||
|
||||
@BeanProperty(
|
||||
bound = childFlag,
|
||||
expert = childFlag,
|
||||
hidden = childFlag,
|
||||
preferred = childFlag,
|
||||
required = childFlag,
|
||||
visualUpdate = childFlag,
|
||||
description = "CHILDPROPERTY",
|
||||
enumerationValues = {"javax.swing.SwingConstants.BOTTOM"}
|
||||
)
|
||||
@Override
|
||||
public void setX(int v) { x = v; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {}
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {}
|
||||
}
|
||||
|
||||
public static class Base {
|
||||
private int x;
|
||||
public void setX(int v) { x = v; }
|
||||
public int getX() { return x; }
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {}
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {}
|
||||
}
|
||||
|
||||
public static class BaseBeanInfo extends SimpleBeanInfo {
|
||||
|
||||
@Override
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
BeanDescriptor d = new BeanDescriptor(Base.class, null);
|
||||
d.setShortDescription("BASE");
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
PropertyDescriptor[] p = new PropertyDescriptor[1];
|
||||
|
||||
try {
|
||||
p[0] = new PropertyDescriptor ("x", Base.class, "getX", null);
|
||||
p[0].setShortDescription("BASEPROPERTY");
|
||||
p[0].setBound (baseFlag);
|
||||
p[0].setExpert(baseFlag);
|
||||
p[0].setHidden(baseFlag);
|
||||
p[0].setPreferred(baseFlag);
|
||||
p[0].setValue("required", baseFlag);
|
||||
p[0].setValue("visualUpdate", baseFlag);
|
||||
p[0].setValue("enumerationValues",
|
||||
new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
|
||||
} catch(IntrospectionException e) { e.printStackTrace(); }
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }
|
||||
@Override
|
||||
public MethodDescriptor[] getMethodDescriptors() {
|
||||
MethodDescriptor[] m = new MethodDescriptor[1];
|
||||
try {
|
||||
m[0] = new MethodDescriptor(Base.class.getMethod("setX", new Class[] {int.class}));
|
||||
m[0].setDisplayName("");
|
||||
}
|
||||
catch( NoSuchMethodException e) {}
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPropertyIndex() { return -1; }
|
||||
@Override
|
||||
public int getDefaultEventIndex() { return -1; }
|
||||
@Override
|
||||
public java.awt.Image getIcon(int iconKind) { return null; }
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
|
||||
Checker.checkEq("description",
|
||||
i.getBeanDescriptor().getShortDescription(), "CHILD");
|
||||
|
||||
PropertyDescriptor[] pds = i.getPropertyDescriptors();
|
||||
Checker.checkEq("number of properties", pds.length, 1);
|
||||
PropertyDescriptor p = pds[0];
|
||||
|
||||
Checker.checkEq("property description", p.getShortDescription(), "CHILDPROPERTY");
|
||||
Checker.checkEq("isBound", p.isBound(), childFlag);
|
||||
Checker.checkEq("isExpert", p.isExpert(), childFlag);
|
||||
Checker.checkEq("isHidden", p.isHidden(), childFlag);
|
||||
Checker.checkEq("isPreferred", p.isPreferred(), childFlag);
|
||||
Checker.checkEq("required", p.getValue("required"), childFlag);
|
||||
Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), childFlag);
|
||||
|
||||
Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),
|
||||
new Object[]{"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2024, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8159696
|
||||
* @library /javax/swing/regtesthelpers
|
||||
* @compile ./stub/Stub.java
|
||||
* @run main/othervm -Xmx32M UnloadClassBeanInfo
|
||||
*/
|
||||
public class UnloadClassBeanInfo {
|
||||
|
||||
private static URLClassLoader loader;
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
Class cl = getStub();
|
||||
System.out.println("cl.getClassLoader() = " + cl.getClassLoader());
|
||||
final BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);
|
||||
MethodDescriptor[] mds = beanInfo.getMethodDescriptors();
|
||||
System.out.println("mds = " + Arrays.toString(mds));
|
||||
loader.close();
|
||||
loader=null;
|
||||
cl=null;
|
||||
Util.generateOOME();
|
||||
mds = beanInfo.getMethodDescriptors();
|
||||
System.out.println("mds = " + Arrays.toString(mds));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Stub class is compiled by jtreg, but we want to move it so it is not
|
||||
* on the application classpath. We want to load it through a separate
|
||||
* classloader.
|
||||
*/
|
||||
static Class<?> getStub() throws Exception {
|
||||
final String testclasses = System.getProperty("test.classes");
|
||||
final File subdir = new File(testclasses, "stub");
|
||||
subdir.mkdir();
|
||||
|
||||
final Path src = Paths.get(testclasses, "Stub.class");
|
||||
final Path dest = subdir.toPath().resolve("Stub.class");
|
||||
Files.move(src, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
loader = new URLClassLoader(new URL[]{subdir.toURL()});
|
||||
return Class.forName("Stub", true, loader);
|
||||
}
|
||||
}
|
||||
29
test/jdk/java/beans/Introspector/8159696/stub/Stub.java
Normal file
29
test/jdk/java/beans/Introspector/8159696/stub/Stub.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
public final class Stub {
|
||||
|
||||
public void test() {
|
||||
|
||||
}
|
||||
}
|
||||
1007
test/jdk/java/beans/Introspector/AnonymousClassBeanPropertyTest.java
Normal file
1007
test/jdk/java/beans/Introspector/AnonymousClassBeanPropertyTest.java
Normal file
File diff suppressed because it is too large
Load diff
1085
test/jdk/java/beans/Introspector/BeanPropertyTest.java
Normal file
1085
test/jdk/java/beans/Introspector/BeanPropertyTest.java
Normal file
File diff suppressed because it is too large
Load diff
203
test/jdk/java/beans/Introspector/BeanUtils.java
Normal file
203
test/jdk/java/beans/Introspector/BeanUtils.java
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2008, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* This class contains utilities useful for JavaBeans regression testing.
|
||||
*/
|
||||
public final class BeanUtils {
|
||||
/**
|
||||
* Disables instantiation.
|
||||
*/
|
||||
private BeanUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bean descriptor for specified class.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @return a bean descriptor
|
||||
*/
|
||||
public static BeanDescriptor getBeanDescriptor(Class type) {
|
||||
try {
|
||||
return Introspector.getBeanInfo(type).getBeanDescriptor();
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of property descriptors for specified class.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @return an array of property descriptors
|
||||
*/
|
||||
public static PropertyDescriptor[] getPropertyDescriptors(Class type) {
|
||||
try {
|
||||
return Introspector.getBeanInfo(type).getPropertyDescriptors();
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event set descriptors for specified class.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @return an array of event set descriptors
|
||||
*/
|
||||
public static EventSetDescriptor[] getEventSetDescriptors(Class type) {
|
||||
try {
|
||||
return Introspector.getBeanInfo(type).getEventSetDescriptors();
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an event set descriptor for the class
|
||||
* that matches the event set name.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the name of the event set to search
|
||||
* @return the {@code EventSetDescriptor} or {@code null}
|
||||
*/
|
||||
public static EventSetDescriptor findEventSetDescriptor(Class type, String name) {
|
||||
EventSetDescriptor[] esds = getEventSetDescriptors(type);
|
||||
for (EventSetDescriptor esd : esds) {
|
||||
if (esd.getName().equals(name)) {
|
||||
return esd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a property descriptor for the class
|
||||
* that matches the property name.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the name of the property to search
|
||||
* @return the {@code PropertyDescriptor}, {@code IndexedPropertyDescriptor} or {@code null}
|
||||
*/
|
||||
public static PropertyDescriptor findPropertyDescriptor(Class type, String name) {
|
||||
PropertyDescriptor[] pds = getPropertyDescriptors(type);
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (pd.getName().equals(name)) {
|
||||
return pd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a event set descriptor for the class
|
||||
* that matches the property name.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the name of the event set to search
|
||||
* @return the {@code EventSetDescriptor}
|
||||
*/
|
||||
public static EventSetDescriptor getEventSetDescriptor(Class type, String name) {
|
||||
EventSetDescriptor esd = findEventSetDescriptor(type, name);
|
||||
if (esd != null) {
|
||||
return esd;
|
||||
}
|
||||
throw new Error("could not find event set '" + name + "' in " + type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a property descriptor for the class
|
||||
* that matches the property name.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the name of the property to search
|
||||
* @return the {@code PropertyDescriptor}
|
||||
*/
|
||||
public static PropertyDescriptor getPropertyDescriptor(Class type, String name) {
|
||||
PropertyDescriptor pd = findPropertyDescriptor(type, name);
|
||||
if (pd != null) {
|
||||
return pd;
|
||||
}
|
||||
throw new Error("could not find property '" + name + "' in " + type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an indexed property descriptor for the class
|
||||
* that matches the property name.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the name of the property to search
|
||||
* @return the {@code IndexedPropertyDescriptor}
|
||||
*/
|
||||
public static IndexedPropertyDescriptor getIndexedPropertyDescriptor(Class type, String name) {
|
||||
PropertyDescriptor pd = findPropertyDescriptor(type, name);
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
return (IndexedPropertyDescriptor) pd;
|
||||
}
|
||||
reportPropertyDescriptor(pd);
|
||||
throw new Error("could not find indexed property '" + name + "' in " + type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports all the interesting information in an Indexed/PropertyDescrptor.
|
||||
*/
|
||||
public static void reportPropertyDescriptor(PropertyDescriptor pd) {
|
||||
System.out.println("property name: " + pd.getName());
|
||||
System.out.println(" type: " + pd.getPropertyType());
|
||||
System.out.println(" read: " + pd.getReadMethod());
|
||||
System.out.println(" write: " + pd.getWriteMethod());
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
System.out.println(" indexed type: " + ipd.getIndexedPropertyType());
|
||||
System.out.println(" indexed read: " + ipd.getIndexedReadMethod());
|
||||
System.out.println(" indexed write: " + ipd.getIndexedWriteMethod());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports all the interesting information in an EventSetDescriptor
|
||||
*/
|
||||
public static void reportEventSetDescriptor(EventSetDescriptor esd) {
|
||||
System.out.println("event set name: " + esd.getName());
|
||||
System.out.println(" listener type: " + esd.getListenerType());
|
||||
System.out.println(" method get: " + esd.getGetListenerMethod());
|
||||
System.out.println(" method add: " + esd.getAddListenerMethod());
|
||||
System.out.println(" method remove: " + esd.getRemoveListenerMethod());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports all the interesting information in a MethodDescriptor
|
||||
*/
|
||||
public static void reportMethodDescriptor(MethodDescriptor md) {
|
||||
System.out.println("method name: " + md.getName());
|
||||
System.out.println(" method: " + md.getMethod());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,577 @@
|
|||
/*
|
||||
* Copyright (c) 2023, 2025, 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 8071693 8347826
|
||||
* @summary Verify that the Introspector finds default methods inherited
|
||||
* from interfaces
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DefaultMethodBeanPropertyTest {
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 1 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A1 {
|
||||
default int getValue() {
|
||||
return 0;
|
||||
}
|
||||
default Object getObj() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getStaticValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public interface B1 extends A1 {
|
||||
}
|
||||
|
||||
public interface C1 extends A1 {
|
||||
Number getFoo();
|
||||
}
|
||||
|
||||
public class D1 implements C1 {
|
||||
@Override
|
||||
public Integer getFoo() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Float getObj() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario1() {
|
||||
verifyMethods(D1.class,
|
||||
"public static int DefaultMethodBeanPropertyTest$A1.getStaticValue()",
|
||||
"public default int DefaultMethodBeanPropertyTest$A1.getValue()",
|
||||
"public java.lang.Integer DefaultMethodBeanPropertyTest$D1.getFoo()",
|
||||
"public java.lang.Float DefaultMethodBeanPropertyTest$D1.getObj()"
|
||||
);
|
||||
verifyProperties(D1.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public default int DefaultMethodBeanPropertyTest$A1.getValue()",
|
||||
"public java.lang.Integer DefaultMethodBeanPropertyTest$D1.getFoo()",
|
||||
"public java.lang.Float DefaultMethodBeanPropertyTest$D1.getObj()"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 2 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A2 {
|
||||
default Object getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public interface B2 extends A2 {
|
||||
}
|
||||
|
||||
public interface C2 extends A2 {
|
||||
}
|
||||
|
||||
public class D2 implements B2, C2 {
|
||||
}
|
||||
|
||||
public static void testScenario2() {
|
||||
verifyMethods(D2.class,
|
||||
"public default java.lang.Object DefaultMethodBeanPropertyTest$A2.getFoo()"
|
||||
);
|
||||
verifyProperties(D2.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public default java.lang.Object DefaultMethodBeanPropertyTest$A2.getFoo()"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 3 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A3 {
|
||||
default Object getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public interface B3 extends A3 {
|
||||
@Override
|
||||
Set<?> getFoo();
|
||||
}
|
||||
|
||||
public interface C3 extends A3 {
|
||||
@Override
|
||||
Collection<?> getFoo();
|
||||
}
|
||||
|
||||
public class D3 implements B3, C3 {
|
||||
@Override
|
||||
public NavigableSet<?> getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario3() {
|
||||
verifyMethods(D3.class,
|
||||
"public java.util.NavigableSet DefaultMethodBeanPropertyTest$D3.getFoo()"
|
||||
);
|
||||
verifyProperties(D3.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public java.util.NavigableSet DefaultMethodBeanPropertyTest$D3.getFoo()"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 4 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A4 {
|
||||
default Object getDefault0() {
|
||||
return null;
|
||||
}
|
||||
default Object getDefault1() {
|
||||
return null;
|
||||
}
|
||||
default Object getDefault2() {
|
||||
return null;
|
||||
}
|
||||
default Object getDefault3() {
|
||||
return null;
|
||||
}
|
||||
Object getNonDefault();
|
||||
}
|
||||
|
||||
public class B4 implements A4 {
|
||||
@Override
|
||||
public Object getDefault1() {
|
||||
return new B4();
|
||||
}
|
||||
@Override
|
||||
public String getDefault2() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Float getDefault3() {
|
||||
return null;
|
||||
}
|
||||
public Long getNonDefault() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario4() {
|
||||
verifyMethods(B4.class,
|
||||
"public default java.lang.Object DefaultMethodBeanPropertyTest$A4.getDefault0()",
|
||||
"public java.lang.Object DefaultMethodBeanPropertyTest$B4.getDefault1()",
|
||||
"public java.lang.String DefaultMethodBeanPropertyTest$B4.getDefault2()",
|
||||
"public java.lang.Float DefaultMethodBeanPropertyTest$B4.getDefault3()",
|
||||
"public java.lang.Long DefaultMethodBeanPropertyTest$B4.getNonDefault()"
|
||||
);
|
||||
verifyProperties(B4.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public default java.lang.Object DefaultMethodBeanPropertyTest$A4.getDefault0()",
|
||||
"public java.lang.Object DefaultMethodBeanPropertyTest$B4.getDefault1()",
|
||||
"public java.lang.String DefaultMethodBeanPropertyTest$B4.getDefault2()",
|
||||
"public java.lang.Float DefaultMethodBeanPropertyTest$B4.getDefault3()",
|
||||
"public java.lang.Long DefaultMethodBeanPropertyTest$B4.getNonDefault()"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 5 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A5 {
|
||||
public default void setParentFoo(Integer num) {
|
||||
}
|
||||
public default void setFoo(String num) {
|
||||
}
|
||||
public static int getStaticValue() {
|
||||
return 0;
|
||||
}
|
||||
private int getPrivateValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class B5 implements A5 {
|
||||
public void setFoo(Number num) {
|
||||
}
|
||||
public void setLocalFoo(Long num) {
|
||||
}
|
||||
public static int getStaticValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario5() {
|
||||
verifyMethods(B5.class,
|
||||
"public static int DefaultMethodBeanPropertyTest$B5.getStaticValue()",
|
||||
"public default void DefaultMethodBeanPropertyTest$A5.setFoo(java.lang.String)",
|
||||
"public default void DefaultMethodBeanPropertyTest$A5.setParentFoo(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$B5.setFoo(java.lang.Number)",
|
||||
"public void DefaultMethodBeanPropertyTest$B5.setLocalFoo(java.lang.Long)"
|
||||
);
|
||||
verifyProperties(B5.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public default void DefaultMethodBeanPropertyTest$A5.setParentFoo(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$B5.setFoo(java.lang.Number)",
|
||||
"public void DefaultMethodBeanPropertyTest$B5.setLocalFoo(java.lang.Long)"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 6 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public class A6 {
|
||||
public void setParentFoo(Integer num) {
|
||||
}
|
||||
public void setFoo(Integer num) {
|
||||
}
|
||||
public static int getStaticValue() {
|
||||
return 0;
|
||||
}
|
||||
private int getPrivateValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class B6 extends A6 {
|
||||
public void setFoo(String num) {
|
||||
}
|
||||
public void setLocalFoo(Long num) {
|
||||
}
|
||||
public static int getStaticValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario6() {
|
||||
verifyMethods(B6.class,
|
||||
"public static int DefaultMethodBeanPropertyTest$B6.getStaticValue()",
|
||||
"public void DefaultMethodBeanPropertyTest$A6.setFoo(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$A6.setParentFoo(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$B6.setFoo(java.lang.String)",
|
||||
"public void DefaultMethodBeanPropertyTest$B6.setLocalFoo(java.lang.Long)"
|
||||
);
|
||||
verifyProperties(B6.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public void DefaultMethodBeanPropertyTest$A6.setParentFoo(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$B6.setFoo(java.lang.String)",
|
||||
"public void DefaultMethodBeanPropertyTest$B6.setLocalFoo(java.lang.Long)"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 7 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
interface A7<T> {
|
||||
T getValue();
|
||||
}
|
||||
|
||||
interface B7 {
|
||||
Runnable getValue();
|
||||
}
|
||||
|
||||
interface AB7 extends B7, A7<Object> {
|
||||
Runnable getValue();
|
||||
}
|
||||
|
||||
abstract class D7 implements AB7 {
|
||||
public void setValue(Runnable value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario7() {
|
||||
verifyMethods(D7.class,
|
||||
"public void DefaultMethodBeanPropertyTest$D7.setValue(java.lang.Runnable)"
|
||||
);
|
||||
verifyProperties(D7.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public void DefaultMethodBeanPropertyTest$D7.setValue(java.lang.Runnable)"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 8 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public interface A8 {
|
||||
public default void setFoo(Float num) {
|
||||
}
|
||||
public default void setFoo2(Integer num) {
|
||||
}
|
||||
}
|
||||
public interface B8 extends A8 {
|
||||
public default void setFoo(Integer num) {
|
||||
}
|
||||
public default void setFoo2(Float num) {
|
||||
}
|
||||
}
|
||||
|
||||
public class C8 implements B8 {
|
||||
}
|
||||
|
||||
public static void testScenario8() {
|
||||
verifyMethods(C8.class,
|
||||
"public default void DefaultMethodBeanPropertyTest$A8.setFoo(java.lang.Float)",
|
||||
"public default void DefaultMethodBeanPropertyTest$A8.setFoo2(java.lang.Integer)",
|
||||
"public default void DefaultMethodBeanPropertyTest$B8.setFoo(java.lang.Integer)",
|
||||
"public default void DefaultMethodBeanPropertyTest$B8.setFoo2(java.lang.Float)"
|
||||
);
|
||||
verifyProperties(C8.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public default void DefaultMethodBeanPropertyTest$B8.setFoo(java.lang.Integer)",
|
||||
"public default void DefaultMethodBeanPropertyTest$B8.setFoo2(java.lang.Float)"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 9 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public class A9 {
|
||||
public void setFoo(Object value) {
|
||||
}
|
||||
public void setFoo(String value) {
|
||||
}
|
||||
public void setFoo2(Object value) {
|
||||
}
|
||||
public void setFoo2(Integer value) {
|
||||
}
|
||||
// For the same setters with inconvertible arg types PropertyInfo behavior is undefined.
|
||||
// public void setLocalFoo3(Long num) { }
|
||||
// public void setLocalFoo3(Float num) { }
|
||||
}
|
||||
|
||||
public static void testScenario9() {
|
||||
verifyMethods(A9.class,
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo(java.lang.String)",
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo(java.lang.Object)",
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo2(java.lang.Integer)",
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo2(java.lang.Object)"
|
||||
);
|
||||
verifyProperties(A9.class,
|
||||
"public final native java.lang.Class java.lang.Object.getClass()",
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo(java.lang.String)",
|
||||
"public void DefaultMethodBeanPropertyTest$A9.setFoo2(java.lang.Integer)"
|
||||
);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// //
|
||||
// SCENARIO 10 //
|
||||
// //
|
||||
//////////////////////////////////////
|
||||
|
||||
public static class A10 {
|
||||
public Object getProp() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface B10 {
|
||||
Object getProp();
|
||||
}
|
||||
|
||||
public static class C10_1 extends A10 implements B10 {
|
||||
}
|
||||
|
||||
public static class C10_2 extends A10 implements B10 {
|
||||
}
|
||||
|
||||
public static class A10BeanInfo extends SimpleBeanInfo {
|
||||
public MethodDescriptor[] getMethodDescriptors() {
|
||||
try {
|
||||
Class params[] = {};
|
||||
MethodDescriptor md = new MethodDescriptor(A10.class.getDeclaredMethod("getProp", params));
|
||||
md.setDisplayName("display name");
|
||||
MethodDescriptor res[] = { md };
|
||||
return res;
|
||||
} catch (Exception exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class C10_1BeanInfo extends SimpleBeanInfo {
|
||||
public BeanInfo[] getAdditionalBeanInfo() {
|
||||
try {
|
||||
BeanInfo res[] = {
|
||||
Introspector.getBeanInfo(A10.class),
|
||||
Introspector.getBeanInfo(B10.class)
|
||||
};
|
||||
return res;
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class C10_2BeanInfo extends SimpleBeanInfo {
|
||||
public BeanInfo[] getAdditionalBeanInfo() {
|
||||
try {
|
||||
BeanInfo res[] = {
|
||||
Introspector.getBeanInfo(B10.class),
|
||||
Introspector.getBeanInfo(A10.class)
|
||||
};
|
||||
return res;
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void testScenario10() {
|
||||
{
|
||||
var md = getMethodDescriptor(C10_1.class, A10.class, "getProp");
|
||||
assertEquals("display name", md.getDisplayName(), "getDisplayName()");
|
||||
}
|
||||
{
|
||||
var md = getMethodDescriptor(C10_2.class, A10.class, "getProp");
|
||||
assertEquals("display name", md.getDisplayName(), "getDisplayName()");
|
||||
}
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
private static void verifyEquality(String title, Set<String> expected, Set<String> actual) {
|
||||
if (!actual.equals(expected)) {
|
||||
throw new Error(title + " mismatch: "
|
||||
+ "\nACTUAL:\n "
|
||||
+ actual.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining("\n "))
|
||||
+ "\nEXPECTED:\n "
|
||||
+ expected.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining("\n ")));
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyProperties(Class<?> type, String... methodNames) {
|
||||
try {
|
||||
final Set<String> expected = new HashSet<>(Arrays.asList(methodNames));
|
||||
final Set<String> actual = Arrays
|
||||
.stream(Introspector.getBeanInfo(type)
|
||||
.getPropertyDescriptors())
|
||||
.flatMap(pd -> Stream.of(pd.getReadMethod(), pd.getWriteMethod()))
|
||||
.filter(Objects::nonNull)
|
||||
.map((Method m) -> m.toString())
|
||||
.collect(Collectors.toSet());
|
||||
verifyEquality("properties", expected, actual);
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyMethods(Class<?> type, String... methodNames) {
|
||||
try {
|
||||
final Set<String> expected = new HashSet<>(Arrays.asList(methodNames));
|
||||
final Set<String> actual = Arrays
|
||||
.stream(Introspector.getBeanInfo(type, Object.class)
|
||||
.getMethodDescriptors())
|
||||
.map(MethodDescriptor::getMethod)
|
||||
.map(Method::toString)
|
||||
.collect(Collectors.toSet());
|
||||
verifyEquality("methods", expected, actual);
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodDescriptor getMethodDescriptor(Class cls, Class stop, String name) {
|
||||
try {
|
||||
for (var md : Introspector.getBeanInfo(cls, stop).getMethodDescriptors()) {
|
||||
if (md.getName().equals(name)) {
|
||||
return md;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertEquals(Object expected, Object actual, String msg) {
|
||||
if (!expected.equals(actual)) {
|
||||
throw new Error(msg + ":\nACTUAL: " + actual + "\nEXPECTED: " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
// Main method
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testScenario1();
|
||||
testScenario2();
|
||||
testScenario3();
|
||||
testScenario4();
|
||||
testScenario5();
|
||||
testScenario6();
|
||||
testScenario7();
|
||||
testScenario8();
|
||||
testScenario9();
|
||||
testScenario10();
|
||||
}
|
||||
}
|
||||
97
test/jdk/java/beans/Introspector/FlushClassInfoCache.java
Normal file
97
test/jdk/java/beans/Introspector/FlushClassInfoCache.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8231454
|
||||
* @summary Tests cache cleanup by the Introspector.flushXXX()
|
||||
*/
|
||||
public final class FlushClassInfoCache {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
verify(getLoader("testClass"));
|
||||
verify(getLoader("testAll"));
|
||||
Reference<ClassLoader> loader = getLoader("test");
|
||||
// Clear the cache in com.sun.beans.introspect.ClassInfo::CACHE
|
||||
Introspector.flushCaches();
|
||||
verify(loader);
|
||||
}
|
||||
|
||||
private static void verify(Reference<?> loader) throws Exception {
|
||||
int attempt = 0;
|
||||
while (loader.get() != null) {
|
||||
if (++attempt > 10) {
|
||||
throw new RuntimeException("Too many attempts: " + attempt);
|
||||
}
|
||||
// Cannot generate OOM here, it will clear the CACHE as well
|
||||
System.gc();
|
||||
Thread.sleep(1000);
|
||||
System.out.println("Not freed :(");
|
||||
}
|
||||
}
|
||||
|
||||
public static void test() {
|
||||
try {
|
||||
Introspector.getBeanInfo(FlushClassInfoCache.class);
|
||||
} catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testClass() {
|
||||
try {
|
||||
Introspector.getBeanInfo(FlushClassInfoCache.class);
|
||||
// Clear the cache in com.sun.beans.introspect.ClassInfo::CACHE
|
||||
Introspector.flushFromCaches(FlushClassInfoCache.class);
|
||||
} catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAll() {
|
||||
try {
|
||||
Introspector.getBeanInfo(FlushClassInfoCache.class);
|
||||
// Clear the cache in com.sun.beans.introspect.ClassInfo::CACHE
|
||||
Introspector.flushCaches();
|
||||
} catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Reference<ClassLoader> getLoader(String m) throws Exception {
|
||||
URL url = FlushClassInfoCache.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[]{url}, null);
|
||||
Class<?> cls = Class.forName("FlushClassInfoCache", true, loader);
|
||||
cls.getDeclaredMethod(m).invoke(null);
|
||||
loader.close();
|
||||
return new WeakReference<>(loader);
|
||||
}
|
||||
}
|
||||
148
test/jdk/java/beans/Introspector/GenericPropertyType.java
Normal file
148
test/jdk/java/beans/Introspector/GenericPropertyType.java
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8196373
|
||||
* @summary Introspector should work when generics are used
|
||||
*/
|
||||
public final class GenericPropertyType {
|
||||
|
||||
/// Nothing is overridden
|
||||
static class ParentNo<T> {
|
||||
public T getValue() {return null;}
|
||||
public void setValue(T value) {}
|
||||
}
|
||||
|
||||
static class ChildNoO extends ParentNo<Object> {}
|
||||
static class ChildNoA extends ParentNo<ArithmeticException> {}
|
||||
static class ChildNoS extends ParentNo<String> {}
|
||||
|
||||
/// no get(), set is overridden
|
||||
static class ParentNoGet<T> {
|
||||
protected void setValue(T value) {}
|
||||
}
|
||||
|
||||
static class ChildNoGetO extends ParentNoGet<Object> {
|
||||
@Override
|
||||
public void setValue(Object value) {}
|
||||
}
|
||||
|
||||
static class ChildNoGetA extends ParentNoGet<ArithmeticException> {
|
||||
@Override
|
||||
public void setValue(ArithmeticException value) {}
|
||||
}
|
||||
|
||||
static class ChildNoGetS extends ParentNoGet<String> {
|
||||
@Override
|
||||
public void setValue(String value) {}
|
||||
}
|
||||
|
||||
/// get() exists, set is overridden
|
||||
static class ParentGet<T> {
|
||||
public final T getValue() {return null;}
|
||||
protected void setValue(T value) {}
|
||||
}
|
||||
|
||||
static class ChildGetO extends ParentGet<Object> {
|
||||
@Override
|
||||
public void setValue(Object value) {}
|
||||
}
|
||||
|
||||
static class ChildGetA extends ParentGet<ArithmeticException> {
|
||||
@Override
|
||||
public void setValue(ArithmeticException value) {}
|
||||
}
|
||||
|
||||
static class ChildGetS extends ParentGet<String> {
|
||||
@Override
|
||||
public void setValue(String value) {}
|
||||
}
|
||||
|
||||
/// Both set/get are overridden
|
||||
static class ParentAll<T> {
|
||||
protected T getValue() {return null;}
|
||||
protected void setValue(T value) {}
|
||||
}
|
||||
|
||||
static class ChildAllO extends ParentAll<Object> {
|
||||
@Override
|
||||
public void setValue(Object value) {}
|
||||
@Override
|
||||
public Object getValue() {return null;}
|
||||
}
|
||||
|
||||
static class ChildAllA extends ParentAll<ArithmeticException> {
|
||||
@Override
|
||||
public void setValue(ArithmeticException value) {}
|
||||
@Override
|
||||
public ArithmeticException getValue() {return null;}
|
||||
}
|
||||
|
||||
static class ChildAllS extends ParentAll<String> {
|
||||
@Override
|
||||
public void setValue(String value) {}
|
||||
@Override
|
||||
public String getValue() {return null;}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testProperty(ChildNoGetA.class, ArithmeticException.class);
|
||||
testProperty(ChildNoGetO.class, Object.class);
|
||||
testProperty(ChildNoGetS.class, String.class);
|
||||
|
||||
testProperty(ChildGetA.class, ArithmeticException.class);
|
||||
testProperty(ChildGetO.class, Object.class);
|
||||
testProperty(ChildGetS.class, String.class);
|
||||
|
||||
testProperty(ChildAllA.class, ArithmeticException.class);
|
||||
testProperty(ChildAllO.class, Object.class);
|
||||
testProperty(ChildAllS.class, String.class);
|
||||
|
||||
testProperty(ChildNoA.class, ArithmeticException.class);
|
||||
testProperty(ChildNoO.class, Object.class);
|
||||
testProperty(ChildNoS.class, String.class);
|
||||
}
|
||||
|
||||
private static void testProperty(Class<?> beanClass, Class<?> type) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
|
||||
if (pds.length != 1) {
|
||||
throw new RuntimeException("Wrong number of properties");
|
||||
}
|
||||
PropertyDescriptor pd = pds[0];
|
||||
System.out.println("pd = " + pd);
|
||||
String name = pd.getName();
|
||||
if (!name.equals("value")) {
|
||||
throw new RuntimeException("Wrong name: " + name);
|
||||
}
|
||||
Class<?> propertyType = pd.getPropertyType();
|
||||
if (propertyType != type) {
|
||||
throw new RuntimeException("Wrong property type: " + propertyType);
|
||||
}
|
||||
}
|
||||
}
|
||||
1281
test/jdk/java/beans/Introspector/InheritanceBeanPropertyTest.java
Normal file
1281
test/jdk/java/beans/Introspector/InheritanceBeanPropertyTest.java
Normal file
File diff suppressed because it is too large
Load diff
2038
test/jdk/java/beans/Introspector/MethodOrderException.java
Normal file
2038
test/jdk/java/beans/Introspector/MethodOrderException.java
Normal file
File diff suppressed because it is too large
Load diff
138
test/jdk/java/beans/Introspector/OverloadedSetter.java
Normal file
138
test/jdk/java/beans/Introspector/OverloadedSetter.java
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8196373
|
||||
* @summary behavior of this class is not specified, but it can be used to check
|
||||
* our implementation for accidental changes
|
||||
*/
|
||||
public final class OverloadedSetter {
|
||||
|
||||
class AAA {}
|
||||
class CCC extends AAA {}
|
||||
class BBB extends CCC {}
|
||||
class DDD extends CCC {}
|
||||
|
||||
class ZZZ {}
|
||||
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentADC<T> {
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(CCC value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentACD<T> {
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(DDD value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentDAC<T> {
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(CCC value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentDCA<T> {
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(AAA value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentCAD<T> {
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(DDD value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type.
|
||||
class ParentCDA<T> {
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(AAA value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type and ZZZ will be
|
||||
// skipped because it will be placed at the end of the methods list.
|
||||
class ParentCDAZ<T> {
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(ZZZ value) {}
|
||||
}
|
||||
// DDD will be selected because it is most specific type which related to
|
||||
// the type of getValue(); BBB will be skipped because it is not a type or
|
||||
// subclass of the type returned by getValue();
|
||||
class ParentDACB<T> {
|
||||
public DDD getValue(){return null;}
|
||||
public void setValue(AAA value) {}
|
||||
public void setValue(DDD value) {}
|
||||
public void setValue(CCC value) {}
|
||||
public void setValue(BBB value) {}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(ParentADC.class);
|
||||
test(ParentACD.class);
|
||||
test(ParentDAC.class);
|
||||
test(ParentDCA.class);
|
||||
test(ParentCAD.class);
|
||||
test(ParentCDA.class);
|
||||
test(ParentCDAZ.class);
|
||||
test(ParentDACB.class);
|
||||
}
|
||||
|
||||
private static void test(Class<?> beanClass) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
|
||||
if (pds.length != 1) {
|
||||
throw new RuntimeException("Wrong number of properties");
|
||||
}
|
||||
PropertyDescriptor pd = pds[0];
|
||||
String name = pd.getName();
|
||||
if (!name.equals("value")) {
|
||||
throw new RuntimeException("Wrong name: " + name);
|
||||
}
|
||||
|
||||
Class<?> propertyType = pd.getPropertyType();
|
||||
if (propertyType != DDD.class) {
|
||||
throw new RuntimeException("Wrong property type: " + propertyType);
|
||||
}
|
||||
Method writeMethod = pd.getWriteMethod();
|
||||
if (writeMethod == null) {
|
||||
throw new RuntimeException("Write method is null");
|
||||
}
|
||||
Class<?>[] parameterTypes = writeMethod.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new RuntimeException("Wrong parameters " + parameterTypes);
|
||||
}
|
||||
if (parameterTypes[0] != DDD.class) {
|
||||
throw new RuntimeException("Wrong type: " + parameterTypes[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
124
test/jdk/java/beans/Introspector/OverriddenGenericGetter.java
Normal file
124
test/jdk/java/beans/Introspector/OverriddenGenericGetter.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8196373
|
||||
* @summary Introspector should work with overridden generic getter method
|
||||
*/
|
||||
public final class OverriddenGenericGetter {
|
||||
|
||||
static class Parent<T> {
|
||||
private T value;
|
||||
public T getValue() {return value;}
|
||||
public final void setValue(T value) {this.value = value;}
|
||||
}
|
||||
|
||||
static class ChildO extends Parent<Object> {
|
||||
public ChildO() {}
|
||||
@Override
|
||||
public Object getValue() {return super.getValue();}
|
||||
}
|
||||
|
||||
static class ChildA extends Parent<ArithmeticException> {
|
||||
public ChildA() {}
|
||||
@Override
|
||||
public ArithmeticException getValue() {return super.getValue();}
|
||||
}
|
||||
|
||||
static class ChildS extends Parent<String> {
|
||||
public ChildS() {}
|
||||
@Override
|
||||
public String getValue() {return super.getValue();}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testBehaviour(ChildA.class);
|
||||
testBehaviour(ChildO.class);
|
||||
testBehaviour(ChildS.class);
|
||||
test(ChildA.class, ArithmeticException.class);
|
||||
test(ChildO.class, Object.class);
|
||||
test(ChildS.class, String.class);
|
||||
}
|
||||
|
||||
private static void testBehaviour(Class<?> beanClass) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor pd = beanInfo.getPropertyDescriptors()[0];
|
||||
Object bean = beanClass.getConstructor().newInstance();
|
||||
Method readMethod = pd.getReadMethod();
|
||||
Method writeMethod = pd.getWriteMethod();
|
||||
|
||||
// check roundtrip for default null values
|
||||
writeMethod.invoke(bean,readMethod.invoke(bean));
|
||||
writeMethod.invoke(bean,readMethod.invoke(bean));
|
||||
|
||||
// set property to non-default value
|
||||
// check roundtrip for non-default values
|
||||
Object param = pd.getPropertyType().getConstructor().newInstance();
|
||||
writeMethod.invoke(bean, param);
|
||||
writeMethod.invoke(bean, readMethod.invoke(bean));
|
||||
writeMethod.invoke(bean, readMethod.invoke(bean));
|
||||
}
|
||||
|
||||
private static void test(Class<?> beanClass, Class<?> type) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
|
||||
if (pds.length != 1) {
|
||||
throw new RuntimeException("Wrong number of properties");
|
||||
}
|
||||
PropertyDescriptor pd = pds[0];
|
||||
String name = pd.getName();
|
||||
if (!name.equals("value")) {
|
||||
throw new RuntimeException("Wrong name: " + name);
|
||||
}
|
||||
|
||||
Class<?> propertyType = pd.getPropertyType();
|
||||
if (propertyType != type) {
|
||||
throw new RuntimeException("Wrong property type: " + propertyType);
|
||||
}
|
||||
Method readMethod = pd.getReadMethod();
|
||||
if (readMethod == null) {
|
||||
throw new RuntimeException("Read method is null");
|
||||
}
|
||||
Class<?> returnType = readMethod.getReturnType();
|
||||
if (returnType != type) {
|
||||
throw new RuntimeException("Wrong return type; " + returnType);
|
||||
}
|
||||
Method writeMethod = pd.getWriteMethod();
|
||||
if (writeMethod == null) {
|
||||
throw new RuntimeException("Write method is null");
|
||||
}
|
||||
Class<?>[] parameterTypes = writeMethod.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new RuntimeException("Wrong parameters " + parameterTypes);
|
||||
}
|
||||
if (parameterTypes[0] != Object.class) {
|
||||
throw new RuntimeException("Wrong type: " + parameterTypes[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
127
test/jdk/java/beans/Introspector/OverriddenGenericSetter.java
Normal file
127
test/jdk/java/beans/Introspector/OverriddenGenericSetter.java
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8196373
|
||||
* @summary Introspector should work with overridden generic setter method
|
||||
*/
|
||||
public final class OverriddenGenericSetter {
|
||||
|
||||
static class Parent<T> {
|
||||
private T value;
|
||||
public final T getValue() {return value;}
|
||||
protected void setValue(T value) {this.value = value;}
|
||||
}
|
||||
|
||||
static class ChildO extends Parent<Object> {
|
||||
public ChildO() {}
|
||||
@Override
|
||||
public void setValue(Object value) {super.setValue(value);}
|
||||
}
|
||||
|
||||
// For overridden setXXX javac will generate the "synthetic bridge" method
|
||||
// setValue(Ljava/lang/Object). We will use two different types which may be
|
||||
// placed before/after bridge method.
|
||||
static class ChildA extends Parent<ArithmeticException> {
|
||||
public ChildA() {}
|
||||
@Override
|
||||
public void setValue(ArithmeticException value) {super.setValue(value);}
|
||||
}
|
||||
|
||||
static class ChildS extends Parent<String> {
|
||||
public ChildS() {}
|
||||
@Override
|
||||
public void setValue(String value) {super.setValue(value);}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testBehaviour(ChildA.class);
|
||||
testBehaviour(ChildO.class);
|
||||
testBehaviour(ChildS.class);
|
||||
testProperty(ChildA.class, ArithmeticException.class);
|
||||
testProperty(ChildO.class, Object.class);
|
||||
testProperty(ChildS.class, String.class);
|
||||
}
|
||||
|
||||
private static void testBehaviour(Class<?> beanClass) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor pd = beanInfo.getPropertyDescriptors()[0];
|
||||
Object bean = beanClass.getConstructor().newInstance();
|
||||
Method readMethod = pd.getReadMethod();
|
||||
Method writeMethod = pd.getWriteMethod();
|
||||
|
||||
// check roundtrip for default null values
|
||||
writeMethod.invoke(bean,readMethod.invoke(bean));
|
||||
writeMethod.invoke(bean,readMethod.invoke(bean));
|
||||
|
||||
// set property to non-default value
|
||||
// check roundtrip for non-default values
|
||||
Object param = pd.getPropertyType().getConstructor().newInstance();
|
||||
writeMethod.invoke(bean, param);
|
||||
writeMethod.invoke(bean, readMethod.invoke(bean));
|
||||
writeMethod.invoke(bean, readMethod.invoke(bean));
|
||||
}
|
||||
|
||||
private static void testProperty(Class<?> beanClass, Class<?> type) throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
|
||||
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
|
||||
if (pds.length != 1) {
|
||||
throw new RuntimeException("Wrong number of properties");
|
||||
}
|
||||
PropertyDescriptor pd = pds[0];
|
||||
System.out.println("pd = " + pd);
|
||||
String name = pd.getName();
|
||||
if (!name.equals("value")) {
|
||||
throw new RuntimeException("Wrong name: " + name);
|
||||
}
|
||||
Class<?> propertyType = pd.getPropertyType();
|
||||
if (propertyType != type) {
|
||||
throw new RuntimeException("Wrong property type: " + propertyType);
|
||||
}
|
||||
Method readMethod = pd.getReadMethod();
|
||||
if (readMethod == null) {
|
||||
throw new RuntimeException("Read method is null");
|
||||
}
|
||||
Class<?> returnType = readMethod.getReturnType();
|
||||
if (returnType != Object.class) {
|
||||
throw new RuntimeException("Wrong return type; " + returnType);
|
||||
}
|
||||
Method writeMethod = pd.getWriteMethod();
|
||||
if (writeMethod == null) {
|
||||
throw new RuntimeException("Write method is null");
|
||||
}
|
||||
Class<?>[] parameterTypes = writeMethod.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new RuntimeException("Wrong parameters " + parameterTypes);
|
||||
}
|
||||
if (parameterTypes[0] != type) {
|
||||
throw new RuntimeException("Wrong type: " + parameterTypes[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
test/jdk/java/beans/Introspector/Test4072197.java
Normal file
73
test/jdk/java/beans/Introspector/Test4072197.java
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2007, 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 4072197
|
||||
* @summary Tests for null in the array of listener method names
|
||||
* @author Graham Hamilton
|
||||
*/
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.util.EventObject;
|
||||
|
||||
public class Test4072197 {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new EventSetDescriptor(
|
||||
SourceClass.class,
|
||||
"action",
|
||||
Listener.class,
|
||||
new String[] {"action", "event", null, "dummy"},
|
||||
"addActionListener",
|
||||
"removeActionListener"
|
||||
);
|
||||
} catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
} catch (NullPointerException exception) {
|
||||
return; // we caught the NullPointerException as expected
|
||||
}
|
||||
throw new Error("NullPointerException expected");
|
||||
}
|
||||
|
||||
public static class SourceClass {
|
||||
public void addActionListener(ActionListener listener) {
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Listener {
|
||||
public void action(EventObject event) {
|
||||
}
|
||||
|
||||
public void event(EventObject event) {
|
||||
}
|
||||
|
||||
public void dummy(EventObject event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
67
test/jdk/java/beans/Introspector/Test4144543.java
Normal file
67
test/jdk/java/beans/Introspector/Test4144543.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2007, 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 4144543
|
||||
* @summary Tests that introspection handles multiple setters in any order
|
||||
* @author Janet Koenig
|
||||
*/
|
||||
|
||||
import java.beans.Beans;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test4144543 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class type = Beans.instantiate(null, "Test4144543").getClass();
|
||||
|
||||
// try all the various places that this would break before
|
||||
|
||||
Introspector.getBeanInfo(type);
|
||||
new PropertyDescriptor("value", type);
|
||||
new PropertyDescriptor("value", type, "getValue", "setValue");
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/*
|
||||
* The Introspector expects the return type of the getter method to
|
||||
* match the parameter type of the setter method. So list the setter
|
||||
* method which has a different type (but compatible) first so that
|
||||
* the Introspector will find it first and recognize that it is not
|
||||
* the correct setter method.
|
||||
*/
|
||||
|
||||
public void setValue(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
103
test/jdk/java/beans/Introspector/Test4168833.java
Normal file
103
test/jdk/java/beans/Introspector/Test4168833.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2014, 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 4168833 8034085
|
||||
* @summary Tests that Introspector does not create IndexedPropertyDescriptor
|
||||
* from non-indexed PropertyDescriptor
|
||||
* @author Mark Davidson
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* The base class "color" property
|
||||
* creates both an IndexedPropertyDescriptor which has a conflicting
|
||||
* type for getColor.
|
||||
*/
|
||||
public class Test4168833 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// When the Sub class is introspected,
|
||||
// the property type should be color.
|
||||
// The complete "classic" set of properties
|
||||
// has been completed accross the hierarchy.
|
||||
test(Sub.class);
|
||||
test(Sub2.class);
|
||||
}
|
||||
|
||||
private static void test(Class type) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop");
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
error(pd, type.getSimpleName() + ".prop should not be an indexed property");
|
||||
}
|
||||
if (!pd.getPropertyType().equals(Color.class)) {
|
||||
error(pd, type.getSimpleName() + ".prop type should be a Color");
|
||||
}
|
||||
if (null == pd.getReadMethod()) {
|
||||
error(pd, type.getSimpleName() + ".prop should have classic read method");
|
||||
}
|
||||
if (null == pd.getWriteMethod()) {
|
||||
error(pd, type.getSimpleName() + ".prop should have classic write method");
|
||||
}
|
||||
}
|
||||
|
||||
private static void error(PropertyDescriptor pd, String message) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
public static class Base {
|
||||
public Color getProp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dimension getProp(int i) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sub extends Base {
|
||||
public void setProp(Color c) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Base2 {
|
||||
public void setProp(Color c) {
|
||||
}
|
||||
|
||||
public void setProp(int i, Dimension d) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sub2 extends Base2 {
|
||||
public Color getProp() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
169
test/jdk/java/beans/Introspector/Test4274639.java
Normal file
169
test/jdk/java/beans/Introspector/Test4274639.java
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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 4274639 4305280
|
||||
* @summary Tests PropertyDescriptor/PropertyEditorSupport improvements
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class Test4274639 {
|
||||
private static String STRING_PROPERTY = "string";
|
||||
private static String INTEGER_PROPERTY = "integer";
|
||||
|
||||
private static String STRING_VALUE = "Test Text";
|
||||
private static Integer INTEGER_VALUE = 261074;
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestBean bean = new TestBean(STRING_VALUE);
|
||||
if (!STRING_VALUE.equals(bean.getString()))
|
||||
throw new Error("unexpected string property: " + bean.getString());
|
||||
|
||||
boolean string = false;
|
||||
boolean integer = false;
|
||||
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(bean.getClass())) {
|
||||
String name = pd.getName();
|
||||
System.out.println(" - " + name);
|
||||
if (name.equals(STRING_PROPERTY)) {
|
||||
// This tests createPropertyEditor such that the PropertyEditor
|
||||
// returned will have the bean as the source object.
|
||||
Class type = pd.getPropertyEditorClass();
|
||||
if (!StringEditor.class.equals(type))
|
||||
throw new Error("unexpected property editor type: " + type);
|
||||
|
||||
PropertyEditor editor = pd.createPropertyEditor(bean);
|
||||
if (editor == null)
|
||||
throw new Error("property editor cannot be created");
|
||||
|
||||
if (STRING_VALUE != editor.getValue())
|
||||
throw new Error("unexpected value: " + editor.getValue());
|
||||
|
||||
Object source = ((PropertyEditorSupport) editor).getSource();
|
||||
if (source != bean)
|
||||
throw new Error("unexpected source: " + source);
|
||||
|
||||
string = true;
|
||||
}
|
||||
if (name.equals(INTEGER_PROPERTY)) {
|
||||
// This tests createPropertyEditor such that the PropertyEditor
|
||||
// returned will be just a new instance
|
||||
Class type = pd.getPropertyEditorClass();
|
||||
if (!IntegerEditor.class.equals(type))
|
||||
throw new Error("unexpected property editor type: " + type);
|
||||
|
||||
PropertyEditor editor = pd.createPropertyEditor(bean);
|
||||
if (editor == null)
|
||||
throw new Error("property editor cannot be created");
|
||||
|
||||
if (INTEGER_VALUE != editor.getValue())
|
||||
throw new Error("unexpected value: " + editor.getValue());
|
||||
|
||||
Object source = ((PropertyEditorSupport) editor).getSource();
|
||||
if (source != editor)
|
||||
throw new Error("unexpected source: " + source);
|
||||
|
||||
integer = true;
|
||||
}
|
||||
}
|
||||
if (!string)
|
||||
throw new Error("string property is not tested");
|
||||
|
||||
if (!integer)
|
||||
throw new Error("integer property is not tested");
|
||||
}
|
||||
|
||||
public static final class TestBean {
|
||||
private String string;
|
||||
private int integer;
|
||||
|
||||
public TestBean() {
|
||||
this.string = "default";
|
||||
this.integer = 0;
|
||||
}
|
||||
|
||||
public TestBean(String string) {
|
||||
setString(string);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
|
||||
public void setString(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public int getInteger() {
|
||||
return this.integer;
|
||||
}
|
||||
|
||||
public void setInteger(int integer) {
|
||||
this.integer = integer;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestBeanBeanInfo extends SimpleBeanInfo {
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
PropertyDescriptor[] pds = new PropertyDescriptor[2];
|
||||
try {
|
||||
pds[0] = new PropertyDescriptor(STRING_PROPERTY, TestBean.class);
|
||||
pds[0].setPropertyEditorClass(StringEditor.class);
|
||||
|
||||
pds[1] = new PropertyDescriptor(INTEGER_PROPERTY, TestBean.class);
|
||||
pds[1].setPropertyEditorClass(IntegerEditor.class);
|
||||
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
return pds;
|
||||
}
|
||||
}
|
||||
|
||||
// Public constructor was added for 4305280
|
||||
public static final class StringEditor extends PropertyEditorSupport {
|
||||
public StringEditor(Object source) {
|
||||
super(source);
|
||||
|
||||
if (source instanceof TestBean) {
|
||||
TestBean test = (TestBean) source;
|
||||
setValue(test.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Will use the default public constructor
|
||||
// that uses this property editor as the source.
|
||||
public static final class IntegerEditor extends PropertyEditorSupport {
|
||||
public Object getValue() {
|
||||
return INTEGER_VALUE; // default value is hard coded
|
||||
}
|
||||
}
|
||||
}
|
||||
188
test/jdk/java/beans/Introspector/Test4498236.java
Normal file
188
test/jdk/java/beans/Introspector/Test4498236.java
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 4498236
|
||||
* @summary Tests toString methods
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.beans.IndexedPropertyChangeEvent;
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.ParameterDescriptor;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Test4498236 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PropertyChangeEvent event = new PropertyChangeEvent("source", null, null, null);
|
||||
event.setPropagationId("id");
|
||||
test("[propertyName=null; oldValue=null; newValue=null; propagationId=id; source=source]", event);
|
||||
test("[propertyName=name; oldValue=old; newValue=new; propagationId=null; source=source]",
|
||||
new PropertyChangeEvent("source", "name", "old", "new")
|
||||
);
|
||||
test("[propertyName=array; index=5; oldValue=old; newValue=new; propagationId=null; source=source]",
|
||||
new IndexedPropertyChangeEvent("source", "array", "old", "new", 5)
|
||||
);
|
||||
FeatureDescriptor fd = new FeatureDescriptor();
|
||||
fd.setName("n");
|
||||
fd.setDisplayName("dn");
|
||||
fd.setShortDescription("sd");
|
||||
fd.setPreferred(true);
|
||||
fd.setHidden(true);
|
||||
fd.setExpert(true);
|
||||
fd.setValue("first", "value");
|
||||
test("[name=n; displayName=dn; shortDescription=sd; preferred; hidden; expert; values={first=value}]", fd);
|
||||
test("[name=String; beanClass=class java.lang.String]",
|
||||
new BeanDescriptor(String.class)
|
||||
);
|
||||
test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",
|
||||
new BeanDescriptor(Object.class, String.class)
|
||||
);
|
||||
test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",
|
||||
new BeanDescriptor(Object.class, String.class)
|
||||
);
|
||||
test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object)]",
|
||||
new MethodDescriptor(Object.class.getMethod("equals", Object.class))
|
||||
);
|
||||
test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object); parameterDescriptors={java.beans.ParameterDescriptor[name=null]}]",
|
||||
new MethodDescriptor(Object.class.getMethod("equals", Object.class), new ParameterDescriptor[] {
|
||||
new ParameterDescriptor()
|
||||
})
|
||||
);
|
||||
Class type = KeyListener.class;
|
||||
String[] names = { "keyTyped", "keyPressed", "keyReleased" };
|
||||
Method[] methods = new Method[names.length];
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
methods[i] = type.getMethod(names[i], KeyEvent.class);
|
||||
}
|
||||
test("[name=key; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.getKeyListeners(); addListenerMethod=public void Test4498236.addKeyListener(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.removeKeyListener(java.awt.event.KeyListener)]",
|
||||
new EventSetDescriptor(Test4498236.class, "key", type, names[0])
|
||||
);
|
||||
test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
|
||||
new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove")
|
||||
);
|
||||
test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
|
||||
new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove", "get")
|
||||
);
|
||||
test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
|
||||
new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type))
|
||||
);
|
||||
test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
|
||||
new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type), Test4498236.class.getMethod("get"))
|
||||
);
|
||||
test("[name=value; propertyType=boolean; readMethod=public boolean Test4498236.isValue(); writeMethod=public void Test4498236.setValue(boolean)]",
|
||||
new PropertyDescriptor("value", Test4498236.class)
|
||||
);
|
||||
test("[name=$$$]",
|
||||
new PropertyDescriptor("$$$", Test4498236.class, null, null)
|
||||
);
|
||||
test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",
|
||||
new PropertyDescriptor("$$$", Test4498236.class, "getValue", null)
|
||||
);
|
||||
test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",
|
||||
new PropertyDescriptor("$$$", Test4498236.class, "getValue", "setValue")
|
||||
);
|
||||
test("[name=$$$]",
|
||||
new PropertyDescriptor("$$$", null, null)
|
||||
);
|
||||
test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",
|
||||
new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), null)
|
||||
);
|
||||
test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",
|
||||
new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), Test4498236.class.getMethod("setValue", boolean.class))
|
||||
);
|
||||
test("[name=index; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
|
||||
new IndexedPropertyDescriptor("index", Test4498236.class)
|
||||
);
|
||||
test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
|
||||
new IndexedPropertyDescriptor("$$$", Test4498236.class, "getIndex", "setIndex", "getIndex", "setIndex")
|
||||
);
|
||||
test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
|
||||
new IndexedPropertyDescriptor("$$$", Test4498236.class.getMethod("getIndex"), Test4498236.class.getMethod("setIndex", new int[0].getClass()), Test4498236.class.getMethod("getIndex", int.class), Test4498236.class.getMethod("setIndex", int.class, int.class) )
|
||||
);
|
||||
}
|
||||
|
||||
public void addKeyListener(KeyListener listener) {
|
||||
add(listener);
|
||||
}
|
||||
|
||||
public void removeKeyListener(KeyListener listener) {
|
||||
remove(listener);
|
||||
}
|
||||
|
||||
public KeyListener getKeyListeners() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(KeyListener listener) {
|
||||
}
|
||||
|
||||
public void remove(KeyListener listener) {
|
||||
}
|
||||
|
||||
public KeyListener get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
}
|
||||
|
||||
public int[] getIndex() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getIndex(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setIndex(int index, int value) {
|
||||
}
|
||||
|
||||
public void setIndex(int[] value) {
|
||||
}
|
||||
|
||||
private static void test(String expected, Object object) {
|
||||
String actual = object.toString();
|
||||
if (!actual.equals(object.getClass().getName() + expected)) {
|
||||
throw new Error(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
206
test/jdk/java/beans/Introspector/Test4619536.java
Normal file
206
test/jdk/java/beans/Introspector/Test4619536.java
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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 4619536
|
||||
* @summary Tests resolving the ambiguities in the resolution of IndexedPropertyDescriptors
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Date;
|
||||
|
||||
public class Test4619536 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(A.class, "foo");
|
||||
if (!ipd.getIndexedPropertyType().equals(String.class)) {
|
||||
error(ipd, "A.foo should be String type");
|
||||
}
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(B.class, "foo");
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
error(pd, "B.foo should not be an indexed property");
|
||||
}
|
||||
if (!pd.getPropertyType().equals(Date.class)) {
|
||||
error(pd, "B.foo should be Date type");
|
||||
}
|
||||
pd = BeanUtils.findPropertyDescriptor(Child.class, "foo");
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
error(pd, "Child.foo should not be an indexed property");
|
||||
}
|
||||
pd = BeanUtils.findPropertyDescriptor(Classic.class, "foo");
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
error(pd, "Classic.foo should not be an indexed property");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(Index.class, "foo");
|
||||
if (!hasIPD(ipd)) {
|
||||
error(pd, "Index.foo should have ipd values");
|
||||
}
|
||||
if (hasPD(ipd)) {
|
||||
error(ipd, "Index.foo should not have pd values");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(All.class, "foo");
|
||||
if (!hasPD(ipd) || !hasIPD(ipd)) {
|
||||
error(ipd, "All.foo should have all pd/ipd values");
|
||||
}
|
||||
if (!isValidType(ipd)) {
|
||||
error(ipd, "All.foo pdType should equal ipdType");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(Getter.class, "foo");
|
||||
if (ipd.getReadMethod() == null || ipd.getWriteMethod() != null) {
|
||||
error(ipd, "Getter.foo classic methods incorrect");
|
||||
}
|
||||
if (!isValidType(ipd)) {
|
||||
error(ipd, "Getter.foo pdType should equal ipdType");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(BadGetter.class, "foo");
|
||||
if (hasPD(ipd)) {
|
||||
error(ipd, "BadGetter.foo should not have classic methods");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(Setter.class, "foo");
|
||||
if (ipd.getReadMethod() != null || ipd.getWriteMethod() == null) {
|
||||
error(ipd, "Setter.foo classic methods incorrect");
|
||||
}
|
||||
if (!isValidType(ipd)) {
|
||||
error(ipd, "Setter.foo pdType should equal ipdType");
|
||||
}
|
||||
ipd = BeanUtils.getIndexedPropertyDescriptor(BadSetter.class, "foo");
|
||||
if (hasPD(ipd)) {
|
||||
error(ipd, "BadSetter.foo should not have classic methods");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPD(PropertyDescriptor pd) {
|
||||
if (null == pd.getPropertyType()) {
|
||||
return false;
|
||||
}
|
||||
return (null != pd.getReadMethod())
|
||||
|| (null != pd.getWriteMethod());
|
||||
}
|
||||
|
||||
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
|
||||
if (null == ipd.getIndexedPropertyType()) {
|
||||
return false;
|
||||
}
|
||||
return (null != ipd.getIndexedReadMethod())
|
||||
|| (null != ipd.getIndexedWriteMethod());
|
||||
}
|
||||
|
||||
public static boolean isValidType(IndexedPropertyDescriptor ipd) {
|
||||
Class type = ipd.getPropertyType();
|
||||
return type.isArray() && type.getComponentType().equals(ipd.getIndexedPropertyType());
|
||||
}
|
||||
|
||||
public static void error(PropertyDescriptor pd, String message) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
// Test case from 4619536
|
||||
public static class A {
|
||||
// prop foo on A should be indexed of type String
|
||||
public String getFoo(int x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class B extends A {
|
||||
// prop foo on should be non-indexed of type Date
|
||||
public Date getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Test case from 4812428 (this works in 1.5.0)
|
||||
public static class Parent {
|
||||
public void setFoo(String foo) {
|
||||
}
|
||||
|
||||
public Child getFoo(int index) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Child extends Parent {
|
||||
public Child getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// This class has a complete set of pd
|
||||
public static class Classic {
|
||||
public String[] getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(String[] foo) {
|
||||
}
|
||||
}
|
||||
|
||||
// This class has a complete set of ipd
|
||||
public static class Index {
|
||||
public String getFoo(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(int i, String f) {
|
||||
}
|
||||
}
|
||||
|
||||
// This class adds a proper getter and setter
|
||||
public static class All extends Index {
|
||||
public String[] getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(String[] foo) {
|
||||
}
|
||||
}
|
||||
|
||||
// This class adds a classic getter
|
||||
public static class Getter extends Index {
|
||||
public String[] getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// This class has an alternate getter and should be merged
|
||||
public static class BadGetter extends Index {
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// This class adds a classic setter
|
||||
public static class Setter extends Index {
|
||||
public void setFoo(String[] f) {
|
||||
}
|
||||
}
|
||||
|
||||
// This class has an alternate setter and should be merged
|
||||
public static class BadSetter extends Index {
|
||||
public void setFoo(String f) {
|
||||
}
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/beans/Introspector/Test4619792.java
Normal file
72
test/jdk/java/beans/Introspector/Test4619792.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2007, 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 4619792
|
||||
* @summary Tests property descriptor for the focusable property
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.beans.IntrospectionException;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
/**
|
||||
* The focusable property is new in 1.4 and is a boolean and bound property
|
||||
* implemented in Component with isFocusable and setFocusable.
|
||||
* For some reason, this property is not picked up
|
||||
* by the Introspector all allong the class heirarchy.
|
||||
* <p/>
|
||||
* The MethodDescriptors for a BeanInfo can find
|
||||
* the isFocusable()/setFocusable() methods as part of the set.
|
||||
* <p/>
|
||||
* This has never worked from the earliest days of merlin.
|
||||
*/
|
||||
public class Test4619792 {
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
Class[] types = {
|
||||
Component.class,
|
||||
Container.class,
|
||||
JComponent.class,
|
||||
AbstractButton.class,
|
||||
JButton.class,
|
||||
JToggleButton.class,
|
||||
};
|
||||
// Control set. "enabled" and "name" has the same pattern and can be found
|
||||
String[] names = {
|
||||
"enabled",
|
||||
"name",
|
||||
"focusable",
|
||||
};
|
||||
for (String name : names) {
|
||||
for (Class type : types) {
|
||||
BeanUtils.getPropertyDescriptor(type, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
143
test/jdk/java/beans/Introspector/Test4634390.java
Normal file
143
test/jdk/java/beans/Introspector/Test4634390.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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 4634390
|
||||
* @summary Tests contract for equals and hashCode methods
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Test4634390 {
|
||||
|
||||
private static final Class[] CLASSES = {
|
||||
JButton.class,
|
||||
JDialog.class,
|
||||
JMenu.class,
|
||||
JPanel.class,
|
||||
JProgressBar.class,
|
||||
JSlider.class,
|
||||
JTable.class,
|
||||
JTree.class,
|
||||
JComboBox.class,
|
||||
JToolBar.class,
|
||||
JTabbedPane.class,
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (Class type : CLASSES) {
|
||||
test(type);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class type) {
|
||||
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) {
|
||||
PropertyDescriptor pdCopy = create(pd);
|
||||
if (pdCopy != null) {
|
||||
// XXX - hack! The Introspector will set the bound property
|
||||
// since it assumes that propertyChange event set descriptors
|
||||
// infers that all the properties are bound
|
||||
pdCopy.setBound(pd.isBound());
|
||||
|
||||
String name = pd.getName();
|
||||
System.out.println(" - " + name);
|
||||
|
||||
if (!compare(pd, pdCopy))
|
||||
throw new Error("property delegates are not equal");
|
||||
|
||||
if (!pd.equals(pdCopy))
|
||||
throw new Error("equals() failed");
|
||||
|
||||
if (pd.hashCode() != pdCopy.hashCode())
|
||||
throw new Error("hashCode() failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyDescriptor create(PropertyDescriptor pd) {
|
||||
try {
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
return new IndexedPropertyDescriptor(
|
||||
ipd.getName(),
|
||||
ipd.getReadMethod(),
|
||||
ipd.getWriteMethod(),
|
||||
ipd.getIndexedReadMethod(),
|
||||
ipd.getIndexedWriteMethod());
|
||||
} else {
|
||||
return new PropertyDescriptor(
|
||||
pd.getName(),
|
||||
pd.getReadMethod(),
|
||||
pd.getWriteMethod());
|
||||
}
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean compare(PropertyDescriptor pd1, PropertyDescriptor pd2) {
|
||||
if (!compare(pd1.getReadMethod(), pd2.getReadMethod())) {
|
||||
System.out.println("read methods not equal");
|
||||
return false;
|
||||
}
|
||||
if (!compare(pd1.getWriteMethod(), pd2.getWriteMethod())) {
|
||||
System.out.println("write methods not equal");
|
||||
return false;
|
||||
}
|
||||
if (pd1.getPropertyType() != pd2.getPropertyType()) {
|
||||
System.out.println("property type not equal");
|
||||
return false;
|
||||
}
|
||||
if (pd1.getPropertyEditorClass() != pd2.getPropertyEditorClass()) {
|
||||
System.out.println("property editor class not equal");
|
||||
return false;
|
||||
}
|
||||
if (pd1.isBound() != pd2.isBound()) {
|
||||
System.out.println("bound value not equal");
|
||||
return false;
|
||||
}
|
||||
if (pd1.isConstrained() != pd2.isConstrained()) {
|
||||
System.out.println("constrained value not equal");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean compare(Method m1, Method m2) {
|
||||
if ((m1 == null) && (m2 == null)) {
|
||||
return true;
|
||||
}
|
||||
if ((m1 == null) || (m2 == null)) {
|
||||
return false;
|
||||
}
|
||||
return m1.equals(m2);
|
||||
}
|
||||
}
|
||||
44
test/jdk/java/beans/Introspector/Test4683761.java
Normal file
44
test/jdk/java/beans/Introspector/Test4683761.java
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2024, 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
|
||||
* @run main Test4683761
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Test4683761 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
60
test/jdk/java/beans/Introspector/Test4896879.java
Normal file
60
test/jdk/java/beans/Introspector/Test4896879.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2008, 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 4896879
|
||||
* @summary Tests for StringIndexOutOfBoundsException in Introspector.getTargetEventInfo()
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public class Test4896879 {
|
||||
public static void main(String[] args) {
|
||||
test(A.class);
|
||||
test(B.class);
|
||||
}
|
||||
|
||||
private static void test(Class type) {
|
||||
if (BeanUtils.getEventSetDescriptors(type).length != 0) {
|
||||
throw new Error("Should not have any EventSetDescriptors");
|
||||
}
|
||||
}
|
||||
|
||||
public static class A implements EventListener {
|
||||
public void addB(B a) {
|
||||
}
|
||||
|
||||
public void removeB(B b) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class B implements EventListener {
|
||||
public void addA(A a) {
|
||||
}
|
||||
|
||||
public void removeA(A a) {
|
||||
}
|
||||
}
|
||||
}
|
||||
146
test/jdk/java/beans/Introspector/Test4918902.java
Normal file
146
test/jdk/java/beans/Introspector/Test4918902.java
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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 4918902
|
||||
* @summary Tests search the most specific methods for PropertyDescriptors
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
|
||||
public class Test4918902 {
|
||||
public static void main(String[] args) {
|
||||
testPropertyDescriptor(Child1.class, Child1.class, Parent.class);
|
||||
testPropertyDescriptor(Child2.class, Parent.class, Child2.class);
|
||||
testPropertyDescriptor(Child3.class, Child3.class, Child3.class);
|
||||
testPropertyDescriptor(Child4.class, Parent.class, Parent.class);
|
||||
|
||||
testPropertyDescriptor(Grandchild.class, Child3.class, Child3.class);
|
||||
|
||||
testIndexedPropertyDescriptor(IChild1.class, IChild1.class, IChild1.class);
|
||||
testIndexedPropertyDescriptor(IChild2.class, IChild2.class, IParent.class);
|
||||
testIndexedPropertyDescriptor(IChild3.class, IParent.class, IChild3.class);
|
||||
testIndexedPropertyDescriptor(IChild4.class, IParent.class, IParent.class);
|
||||
}
|
||||
|
||||
private static void testPropertyDescriptor(Class type, Class read, Class write) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "foo");
|
||||
if (!read.equals(pd.getReadMethod().getDeclaringClass())) {
|
||||
throw new Error("unexpected read method: " + pd.getReadMethod());
|
||||
}
|
||||
if (!write.equals(pd.getWriteMethod().getDeclaringClass())) {
|
||||
throw new Error("unexpected write method: " + pd.getWriteMethod());
|
||||
}
|
||||
}
|
||||
|
||||
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
|
||||
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
|
||||
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
|
||||
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
|
||||
}
|
||||
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
|
||||
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
|
||||
}
|
||||
}
|
||||
|
||||
// simple properties
|
||||
public static class Parent {
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(String str) {
|
||||
}
|
||||
}
|
||||
|
||||
// getter has been overriden
|
||||
public static class Child1 extends Parent {
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// setter has been overriden
|
||||
public static class Child2 extends Parent {
|
||||
public void setFoo(String str) {
|
||||
}
|
||||
}
|
||||
|
||||
// both methods have been overriden
|
||||
public static class Child3 extends Parent {
|
||||
public void setFoo(String str) {
|
||||
}
|
||||
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// methods should be taken from superclass
|
||||
public static class Child4 extends Parent {
|
||||
}
|
||||
|
||||
// methods should be taken from superclass
|
||||
public static class Grandchild extends Child3 {
|
||||
}
|
||||
|
||||
// indexed properties
|
||||
public static class IParent {
|
||||
public String getFoo(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(int i, String str) {
|
||||
}
|
||||
}
|
||||
|
||||
// both methods have been overriden
|
||||
public static class IChild1 extends IParent {
|
||||
public void setFoo(int i, String str) {
|
||||
}
|
||||
|
||||
public String getFoo(int i) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// getter has been overriden
|
||||
public static class IChild2 extends IParent {
|
||||
public String getFoo(int i) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// setter has been overriden
|
||||
public static class IChild3 extends IParent {
|
||||
public void setFoo(int i, String str) {
|
||||
}
|
||||
}
|
||||
|
||||
// methods should be taken from superclass
|
||||
public static class IChild4 extends IParent {
|
||||
}
|
||||
}
|
||||
404
test/jdk/java/beans/Introspector/Test4935607.java
Normal file
404
test/jdk/java/beans/Introspector/Test4935607.java
Normal file
|
|
@ -0,0 +1,404 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2008, 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 %I% %G%
|
||||
* @bug 4935607
|
||||
* @summary Tests transient properties
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.geom.RectangularShape;
|
||||
import java.awt.im.InputContext;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.beans.Transient;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.DefaultListSelectionModel;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
public class Test4935607 {
|
||||
public static void main(String[] args) {
|
||||
// test all possible cases
|
||||
test(Null.class);
|
||||
test(True.class);
|
||||
test(False.class);
|
||||
test(NullNull.class);
|
||||
test(TrueNull.class);
|
||||
test(FalseNull.class);
|
||||
test(NullTrue.class);
|
||||
test(TrueTrue.class);
|
||||
test(FalseTrue.class);
|
||||
test(NullFalse.class);
|
||||
test(TrueFalse.class);
|
||||
test(FalseFalse.class);
|
||||
// test transient properties in AWT
|
||||
test(RectangularShape.class, "frame"); // NON-NLS: getFrame()
|
||||
test(Rectangle.class, "bounds"); // NON-NLS: getBounds()
|
||||
test(Dimension.class, "size"); // NON-NLS: getSize()
|
||||
test(Point.class, "location"); // NON-NLS: getLocation()
|
||||
test(Component.class, "foreground"); // NON-NLS: getForeground()
|
||||
test(Component.class, "background"); // NON-NLS: getBackground()
|
||||
test(Component.class, "font"); // NON-NLS: getFont()
|
||||
test(Component.class, "visible"); // NON-NLS: getVisible()
|
||||
test(ScrollPane.class, "scrollPosition"); // NON-NLS: getScrollPosition()
|
||||
test(InputContext.class, "compositionEnabled"); // NON-NLS: getCompositionEnabled()
|
||||
// test transient properties in Swing
|
||||
test(JComponent.class, "minimumSize"); // NON-NLS: getMinimumSize()
|
||||
test(JComponent.class, "preferredSize"); // NON-NLS: getPreferredSize()
|
||||
test(JComponent.class, "maximumSize"); // NON-NLS: getMaximumSize()
|
||||
test(ImageIcon.class, "image"); // NON-NLS: getImage()
|
||||
test(ImageIcon.class, "imageObserver"); // NON-NLS: getImageObserver()
|
||||
test(JMenuBar.class, "helpMenu"); // NON-NLS: getHelpMenu()
|
||||
test(JScrollPane.class, "verticalScrollBar"); // NON-NLS: getVerticalScrollBar()
|
||||
test(JScrollPane.class, "horizontalScrollBar"); // NON-NLS: getHorizontalScrollBar()
|
||||
test(JScrollPane.class, "rowHeader"); // NON-NLS: getRowHeader()
|
||||
test(JScrollPane.class, "columnHeader"); // NON-NLS: getColumnHeader()
|
||||
test(JViewport.class, "extentSize"); // NON-NLS: getExtentSize()
|
||||
test(JTableHeader.class, "defaultRenderer"); // NON-NLS: getDefaultRenderer()
|
||||
test(JList.class, "cellRenderer"); // NON-NLS: getCellRenderer()
|
||||
test(JList.class, "selectedIndices"); // NON-NLS: getSelectedIndices()
|
||||
test(DefaultListSelectionModel.class, "leadSelectionIndex"); // NON-NLS: getLeadSelectionIndex()
|
||||
test(DefaultListSelectionModel.class, "anchorSelectionIndex"); // NON-NLS: getAnchorSelectionIndex()
|
||||
test(JComboBox.class, "selectedIndex"); // NON-NLS: getSelectedIndex()
|
||||
test(JTabbedPane.class, "selectedIndex"); // NON-NLS: getSelectedIndex()
|
||||
test(JTabbedPane.class, "selectedComponent"); // NON-NLS: getSelectedComponent()
|
||||
test(AbstractButton.class, "disabledIcon"); // NON-NLS: getDisabledIcon()
|
||||
test(JLabel.class, "disabledIcon"); // NON-NLS: getDisabledIcon()
|
||||
test(JTextComponent.class, "caret"); // NON-NLS: getCaret()
|
||||
test(JTextComponent.class, "caretPosition"); // NON-NLS: getCaretPosition()
|
||||
test(JTextComponent.class, "selectionStart"); // NON-NLS: getSelectionStart()
|
||||
test(JTextComponent.class, "selectionEnd"); // NON-NLS: getSelectionEnd()
|
||||
}
|
||||
|
||||
private static void test(Class type) {
|
||||
Object value = getExpectedValue(type);
|
||||
test(value, BeanUtils.getPropertyDescriptor(type, "property")); // NON-NLS: the property to check
|
||||
test(value, BeanUtils.getEventSetDescriptor(type, "eventSet")); // NON-NLS: the event set to check
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private static void test(Class type, String property) {
|
||||
System.out.print(type.getName() + ": ");
|
||||
test(Boolean.TRUE, BeanUtils.getPropertyDescriptor(type, property));
|
||||
}
|
||||
|
||||
private static void test(Object expected, FeatureDescriptor fd) {
|
||||
System.out.println(fd.getName());
|
||||
Object actual = fd.getValue("transient"); // NON-NLS: the attribute name
|
||||
if ((actual == null) ? (expected != null) : !actual.equals(expected))
|
||||
throw new Error("expected " + expected + " value, but actual value is " + actual);
|
||||
}
|
||||
|
||||
private static Object getExpectedValue(Class type) {
|
||||
try {
|
||||
return type.getField("VALUE").get(type); // NON-NLS: the field name with expected value
|
||||
} catch (NoSuchFieldException exception) {
|
||||
return null;
|
||||
} catch (IllegalAccessException exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Null {
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class True {
|
||||
public static final Boolean VALUE = Boolean.TRUE;
|
||||
|
||||
@Transient
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class False {
|
||||
public static final Boolean VALUE = Boolean.FALSE;
|
||||
|
||||
@Transient(false)
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Transient(false)
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Transient(false)
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Transient(false)
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NullNull extends Null {
|
||||
@Override
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrueNull extends Null {
|
||||
public static final Boolean VALUE = Boolean.TRUE;
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FalseNull extends Null {
|
||||
public static final Boolean VALUE = Boolean.FALSE;
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NullTrue extends True {
|
||||
@Override
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrueTrue extends True {
|
||||
@Override
|
||||
@Transient
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FalseTrue extends True {
|
||||
public static final Boolean VALUE = Boolean.FALSE;
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NullFalse extends False {
|
||||
@Override
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrueFalse extends False {
|
||||
public static final Boolean VALUE = Boolean.TRUE;
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FalseFalse extends False {
|
||||
@Override
|
||||
@Transient(false)
|
||||
public Object getProperty() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void setProperty(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void addEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient(false)
|
||||
public void removeEventSetListener(EventSetListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class EventSetListener implements EventListener {
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/Introspector/Test4948761.java
Normal file
53
test/jdk/java/beans/Introspector/Test4948761.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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 4948761
|
||||
* @summary Tests introspection of a primitive types
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test4948761 {
|
||||
private static final Class[] TYPES = {
|
||||
char.class,
|
||||
byte.class,
|
||||
short.class,
|
||||
int.class,
|
||||
long.class,
|
||||
float.class,
|
||||
double.class,
|
||||
boolean.class,
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (Class type : TYPES) {
|
||||
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
|
||||
if (pds.length > 0) {
|
||||
throw new Error("primitive type should not have properties");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/beans/Introspector/Test4984912.java
Normal file
72
test/jdk/java/beans/Introspector/Test4984912.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2007, 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 4984912
|
||||
* @summary Tests property descriptors without getter and setter
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class Test4984912 {
|
||||
public static void main(String[] args) {
|
||||
PropertyDescriptor[] array = BeanUtils.getPropertyDescriptors(SimpleBean.class);
|
||||
for (PropertyDescriptor pd : array) {
|
||||
BeanUtils.reportPropertyDescriptor(pd);
|
||||
}
|
||||
if (array.length != 3)
|
||||
throw new Error("unexpected count of properties: " + array.length);
|
||||
}
|
||||
|
||||
public static class SimpleBean {
|
||||
private int property;
|
||||
|
||||
public int getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(int property) {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleBeanBeanInfo extends SimpleBeanInfo {
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
PropertyDescriptor pdProperty = new PropertyDescriptor("property", SimpleBean.class, "getProperty", "setProperty");
|
||||
PropertyDescriptor pdNullable = new PropertyDescriptor("nullable", SimpleBean.class, null, null);
|
||||
PropertyDescriptor pdIndexed = new IndexedPropertyDescriptor("indexed", SimpleBean.class, null, null, null, null);
|
||||
pdNullable.setValue("name", "value");
|
||||
return new PropertyDescriptor[] {pdProperty, pdNullable, pdIndexed};
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
78
test/jdk/java/beans/Introspector/Test5063390.java
Normal file
78
test/jdk/java/beans/Introspector/Test5063390.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 2007, 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 5063390
|
||||
* @summary Tests the order of Properties
|
||||
* @author Brent Christian
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test5063390 {
|
||||
private int alpha;
|
||||
private int foxtrot;
|
||||
private int zulu;
|
||||
|
||||
public int getZulu() {
|
||||
return zulu;
|
||||
}
|
||||
|
||||
public void setZulu(int zulu) {
|
||||
this.zulu = zulu;
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public int getFoxtrot() {
|
||||
return foxtrot;
|
||||
}
|
||||
|
||||
public void setFoxtrot(int foxtrot) {
|
||||
this.foxtrot = foxtrot;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] names = {"alpha", "class", "foxtrot", "zulu"};
|
||||
|
||||
PropertyDescriptor[] pd = BeanUtils.getPropertyDescriptors(Test5063390.class);
|
||||
if (pd.length != names.length)
|
||||
throw new Error("unexpected count of properties: " + pd.length);
|
||||
|
||||
for (int i = 0; i < pd.length; i++) {
|
||||
String name = pd[i].getName();
|
||||
System.out.println("property: " + name);
|
||||
if (!name.equals(names[i])) {
|
||||
System.out.println("expected: " + names[i]);
|
||||
throw new Error("unexpected order of properties");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
155
test/jdk/java/beans/Introspector/Test5102804.java
Normal file
155
test/jdk/java/beans/Introspector/Test5102804.java
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2024, 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 5102804
|
||||
* @summary Tests memory leak
|
||||
* @run main/othervm -Xms16m -Xmx16m Test5102804
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class Test5102804 {
|
||||
private static final String BEAN_NAME = "Test5102804$Example";
|
||||
private static final String BEAN_INFO_NAME = BEAN_NAME + "BeanInfo";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (!isCollectible(getReference()))
|
||||
throw new Error("Reference is not collected");
|
||||
}
|
||||
|
||||
private static Reference getReference() {
|
||||
try {
|
||||
ClassLoader loader = new Loader();
|
||||
Class type = Class.forName(BEAN_NAME, true, loader);
|
||||
if (!type.getClassLoader().equals(loader)) {
|
||||
throw new Error("Wrong class loader");
|
||||
}
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
if (0 != info.getDefaultPropertyIndex()) {
|
||||
throw new Error("Wrong bean info found");
|
||||
}
|
||||
return new WeakReference<Class>(type);
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("Introspection Error", exception);
|
||||
}
|
||||
catch (ClassNotFoundException exception) {
|
||||
throw new Error("Class Not Found", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCollectible(Reference reference) {
|
||||
int[] array = new int[10];
|
||||
while (true) {
|
||||
try {
|
||||
array = new int[array.length + array.length / 3];
|
||||
}
|
||||
catch (OutOfMemoryError error) {
|
||||
return null == reference.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom class loader to load the Example class by itself.
|
||||
* Could also load it from a different code source, but this is easier to set up.
|
||||
*/
|
||||
private static final class Loader extends URLClassLoader {
|
||||
Loader() {
|
||||
super(new URL[] {
|
||||
Test5102804.class.getProtectionDomain().getCodeSource().getLocation()
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
Class c = findLoadedClass(name);
|
||||
if (c == null) {
|
||||
if (BEAN_NAME.equals(name) || BEAN_INFO_NAME.equals(name)) {
|
||||
c = findClass(name);
|
||||
}
|
||||
else try {
|
||||
c = getParent().loadClass(name);
|
||||
}
|
||||
catch (ClassNotFoundException exception) {
|
||||
c = findClass(name);
|
||||
}
|
||||
}
|
||||
if (resolve) {
|
||||
resolveClass(c);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple bean to load from the Loader class, not main class loader.
|
||||
*/
|
||||
public static final class Example {
|
||||
private int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The BeanInfo for the Example class.
|
||||
* It is also loaded from the Loader class.
|
||||
*/
|
||||
public static final class ExampleBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public int getDefaultPropertyIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
return new PropertyDescriptor[] {
|
||||
new PropertyDescriptor("value", Class.forName(BEAN_NAME))
|
||||
};
|
||||
}
|
||||
catch (ClassNotFoundException exception) {
|
||||
return null;
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
129
test/jdk/java/beans/Introspector/Test6194788.java
Normal file
129
test/jdk/java/beans/Introspector/Test6194788.java
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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 6194788
|
||||
* @summary Tests bound property in PropertyDescriptor/PropertyEditorSupport
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test6194788 {
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
test(Grand.class, new PropertyDescriptor("index", Grand.class));
|
||||
test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName"));
|
||||
|
||||
test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class));
|
||||
test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class));
|
||||
|
||||
test(Child.class, new PropertyDescriptor("childIndex", Child.class));
|
||||
test(Child.class, new IndexedPropertyDescriptor("childName", Child.class));
|
||||
}
|
||||
|
||||
private static void test(Class type, PropertyDescriptor property) {
|
||||
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) {
|
||||
boolean forward = pd.equals(property);
|
||||
boolean backward = property.equals(pd);
|
||||
if (forward || backward) {
|
||||
if (forward && backward)
|
||||
return;
|
||||
|
||||
throw new Error("illegal comparison of properties");
|
||||
}
|
||||
}
|
||||
throw new Error("could not find property: " + property.getName());
|
||||
}
|
||||
|
||||
public static class Grand {
|
||||
public int getIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
}
|
||||
|
||||
public String getName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setName(int index, String name) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Parent {
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
public int getParentIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setParentIndex(int index) {
|
||||
}
|
||||
|
||||
public String[] getParentName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getParentName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setParentName(String[] names) {
|
||||
}
|
||||
|
||||
public void setParentName(int index, String name) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Child {
|
||||
public int getChildIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setChildIndex(int index) {
|
||||
}
|
||||
|
||||
public String[] getChildName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getChildName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setChildName(String[] names) {
|
||||
}
|
||||
|
||||
public void setChildName(int index, String name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/beans/Introspector/Test6311051.java
Normal file
71
test/jdk/java/beans/Introspector/Test6311051.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2007, 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 6311051
|
||||
* @run main/othervm -XX:SoftRefLRUPolicyMSPerMB=0 Test6311051
|
||||
* @summary Tests listener method with many paramenters
|
||||
* @author Peter Zhelezniakov
|
||||
*/
|
||||
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.EventObject;
|
||||
|
||||
public class Test6311051 {
|
||||
public static void main(String[] args) throws IntrospectionException, NoSuchMethodException {
|
||||
EventSetDescriptor esd = new EventSetDescriptor(
|
||||
"foo",
|
||||
FooListener.class,
|
||||
new Method[] {
|
||||
FooListener.class.getMethod("fooHappened", EventObject.class),
|
||||
FooListener.class.getMethod("moreFooHappened", EventObject.class, Object.class),
|
||||
FooListener.class.getMethod("lessFooHappened"),
|
||||
},
|
||||
Bean.class.getMethod("addFooListener", FooListener.class),
|
||||
Bean.class.getMethod("removeFooListener", FooListener.class)
|
||||
);
|
||||
System.gc();
|
||||
for (Method method : esd.getListenerMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean {
|
||||
public void addFooListener(FooListener listener) {
|
||||
}
|
||||
|
||||
public void removeFooListener(FooListener listener) {
|
||||
}
|
||||
}
|
||||
|
||||
public static interface FooListener {
|
||||
void fooHappened(EventObject event);
|
||||
|
||||
void moreFooHappened(EventObject event, Object data);
|
||||
|
||||
void lessFooHappened();
|
||||
}
|
||||
}
|
||||
87
test/jdk/java/beans/Introspector/Test6422403.java
Normal file
87
test/jdk/java/beans/Introspector/Test6422403.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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 6422403
|
||||
* @summary Tests property types for generics
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test6422403 {
|
||||
public static void main(String[] args) {
|
||||
test(Grand.class, "array", new Object[0].getClass());
|
||||
|
||||
test(Parent.class, "array", new Number[0].getClass());
|
||||
test(Parent.class, "number", Number.class);
|
||||
|
||||
test(Child.class, "array", new Long[0].getClass());
|
||||
test(Child.class, "number", Long.class);
|
||||
test(Child.class, "value", Long.class);
|
||||
}
|
||||
|
||||
private static void test(Class type, String name, Class expected) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, name);
|
||||
if (name.equals(pd.getName()))
|
||||
if (!expected.equals(pd.getPropertyType()))
|
||||
throw new Error("expected " + expected + " but " + pd.getPropertyType() + " is resolved");
|
||||
}
|
||||
|
||||
private static class Grand<A> {
|
||||
private A[] array;
|
||||
|
||||
public A[] getArray() {
|
||||
return this.array;
|
||||
}
|
||||
|
||||
public void setArray(A...array) {
|
||||
this.array = array;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Parent<N extends Number> extends Grand<N> {
|
||||
private N number;
|
||||
|
||||
public N getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(N number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Child extends Parent<Long> {
|
||||
private Long value;
|
||||
|
||||
public Long getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
test/jdk/java/beans/Introspector/Test6447751.java
Normal file
100
test/jdk/java/beans/Introspector/Test6447751.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 6447751
|
||||
* @summary Tests automatic search for customizers
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.awt.Component;
|
||||
import java.beans.Customizer;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
public class Test6447751 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Manual.class, AutomaticCustomizer.class);
|
||||
test(Illegal.class, null);
|
||||
test(Automatic.class, AutomaticCustomizer.class);
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, Class<?> expected) {
|
||||
Class<?> actual;
|
||||
try {
|
||||
actual = Introspector.getBeanInfo(type).getBeanDescriptor().getCustomizerClass();
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
if (actual != expected) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("bean ").append(type).append(": ");
|
||||
if (expected != null) {
|
||||
sb.append("expected ").append(expected);
|
||||
if (actual != null) {
|
||||
sb.append(", but ");
|
||||
}
|
||||
}
|
||||
if (actual != null) {
|
||||
sb.append("found ").append(actual);
|
||||
}
|
||||
throw new Error(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Automatic {
|
||||
}
|
||||
public static class AutomaticCustomizer extends Component implements Customizer {
|
||||
public void setObject(Object bean) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Illegal {
|
||||
}
|
||||
public static class IllegalCustomizer implements Customizer {
|
||||
public void setObject(Object bean) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Manual {
|
||||
}
|
||||
public static class ManualBeanInfo extends SimpleBeanInfo {
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
return new BeanDescriptor(Manual.class, AutomaticCustomizer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
test/jdk/java/beans/Introspector/Test6528714.java
Normal file
56
test/jdk/java/beans/Introspector/Test6528714.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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 6528714
|
||||
* @summary Tests two getters with different return types
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test6528714 {
|
||||
public static void main(String[] args) {
|
||||
test(Concrete.class, "id", Integer.class);
|
||||
}
|
||||
|
||||
private static void test(Class type, String name, Class expected) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, name);
|
||||
if (name.equals(pd.getName()))
|
||||
if (!expected.equals(pd.getPropertyType()))
|
||||
throw new Error("expected " + expected + " but " + pd.getPropertyType() + " is resolved");
|
||||
}
|
||||
|
||||
private static interface Abstract {
|
||||
Number getId();
|
||||
}
|
||||
|
||||
private static class Concrete implements Abstract {
|
||||
private Integer id;
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
test/jdk/java/beans/Introspector/Test6660539.java
Normal file
65
test/jdk/java/beans/Introspector/Test6660539.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2011, 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 6660539
|
||||
* @summary Tests changeable BeanInfo cache in different application contexts
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test6660539 implements Runnable {
|
||||
private static final String NAME = "$$$";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (PropertyDescriptor pd : getPropertyDescriptors()) {
|
||||
pd.setDisplayName(NAME);
|
||||
}
|
||||
ThreadGroup group = new ThreadGroup(NAME);
|
||||
Thread thread = new Thread(group, new Test6660539());
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (PropertyDescriptor pd : getPropertyDescriptors()) {
|
||||
if (pd.getDisplayName().equals(NAME))
|
||||
throw new Error("shared BeanInfo cache");
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
BeanInfo info = Introspector.getBeanInfo(Test6660539.class);
|
||||
return info.getPropertyDescriptors();
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
80
test/jdk/java/beans/Introspector/Test6707231.java
Normal file
80
test/jdk/java/beans/Introspector/Test6707231.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6707231
|
||||
* @summary Tests the boolean getter
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test6707231 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(Bean.class, Bean.class);
|
||||
test(Public.class, Public.class);
|
||||
test(Private.class, Bean.class);
|
||||
}
|
||||
|
||||
public static class Bean {
|
||||
private boolean value;
|
||||
|
||||
public boolean isValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Public extends Bean {
|
||||
public boolean isValue() {
|
||||
return super.isValue();
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Private extends Bean {
|
||||
public boolean isValue() {
|
||||
return super.isValue();
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> actual, Class<?> expected) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(actual, "value");
|
||||
Class<?> getter = pd.getReadMethod().getDeclaringClass();
|
||||
Class<?> setter = pd.getWriteMethod().getDeclaringClass();
|
||||
if ((getter != expected) || (setter != expected)) {
|
||||
throw new Error(actual.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
52
test/jdk/java/beans/Introspector/Test6707234.java
Normal file
52
test/jdk/java/beans/Introspector/Test6707234.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 6707234
|
||||
* @summary Tests setter in a complex bean
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test6707234 {
|
||||
public static void main(String[] args) {
|
||||
if (null == BeanUtils.getPropertyDescriptor(C.class, "number").getWriteMethod()) {
|
||||
throw new Error("no write method");
|
||||
}
|
||||
}
|
||||
|
||||
public interface I {
|
||||
void setNumber(Object number);
|
||||
Number getNumber();
|
||||
}
|
||||
|
||||
public class C implements I {
|
||||
public void setNumber(Object value) {
|
||||
}
|
||||
public void setNumber(Long value) {
|
||||
}
|
||||
public Long getNumber() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
test/jdk/java/beans/Introspector/Test6723447.java
Normal file
88
test/jdk/java/beans/Introspector/Test6723447.java
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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 6723447
|
||||
* @summary Tests return type for property setters
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Test6723447 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Test6723447.class);
|
||||
test(BigDecimal.class);
|
||||
}
|
||||
|
||||
private static void test(Class<?> type) {
|
||||
for (PropertyDescriptor pd : getPropertyDescriptors(type)) {
|
||||
test(pd.getWriteMethod());
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
test(ipd.getIndexedWriteMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Method method) {
|
||||
if (method != null) {
|
||||
Class<?> type = method.getReturnType();
|
||||
if (!type.equals(void.class)) {
|
||||
throw new Error("unexpected return type: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyDescriptor[] getPropertyDescriptors(Class<?> type) {
|
||||
try {
|
||||
return Introspector.getBeanInfo(type).getPropertyDescriptors();
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object setValue(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getValues(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object setValues(int index, Object value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
66
test/jdk/java/beans/Introspector/Test6868189.java
Normal file
66
test/jdk/java/beans/Introspector/Test6868189.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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 6868189
|
||||
* @summary Tests custom BeanInfo in the same package
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class Test6868189 {
|
||||
|
||||
private static final String PROPERTY = "$?"; // NON-NLS: the property name
|
||||
private static final String GETTER = "name"; // NON-NLS: the method name
|
||||
private static final String SETTER = null;
|
||||
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
PropertyDescriptor[] pds = Introspector.getBeanInfo(Enumeration.class).getPropertyDescriptors();
|
||||
if ((pds.length != 1)|| !PROPERTY.equals(pds[0].getName())){
|
||||
throw new Error("unexpected property");
|
||||
}
|
||||
}
|
||||
|
||||
public enum Enumeration {
|
||||
FIRST, SECOND
|
||||
}
|
||||
|
||||
public static class EnumerationBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
return new PropertyDescriptor[] {
|
||||
new PropertyDescriptor(PROPERTY, Enumeration.class, GETTER, SETTER)
|
||||
};
|
||||
}
|
||||
catch (IntrospectionException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
78
test/jdk/java/beans/Introspector/Test6963811.java
Normal file
78
test/jdk/java/beans/Introspector/Test6963811.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 6963811
|
||||
* @summary Tests deadlock in Introspector
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class Test6963811 implements Runnable {
|
||||
private final long time;
|
||||
private final boolean sync;
|
||||
|
||||
public Test6963811(long time, boolean sync) {
|
||||
this.time = time;
|
||||
this.sync = sync;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(this.time); // increase the chance of the deadlock
|
||||
Introspector.getBeanInfo(
|
||||
this.sync ? Super.class : Sub.class,
|
||||
this.sync ? null : Object.class);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Thread[] threads = new Thread[2];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new Thread(new Test6963811(0L, i > 0));
|
||||
threads[i].start();
|
||||
Thread.sleep(500L); // increase the chance of the deadlock
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Super {
|
||||
}
|
||||
|
||||
public static class Sub extends Super {
|
||||
}
|
||||
|
||||
public static class SubBeanInfo extends SimpleBeanInfo {
|
||||
public SubBeanInfo() {
|
||||
new Test6963811(1000L, true).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
163
test/jdk/java/beans/Introspector/Test7172865.java
Normal file
163
test/jdk/java/beans/Introspector/Test7172865.java
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7172854 7172865
|
||||
* @summary Tests that cached methods are not lost
|
||||
* @author Sergey Malenkov
|
||||
* @run main/othervm -Xmx128m Test7172865
|
||||
*/
|
||||
|
||||
public class Test7172865 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
int errors = 0;
|
||||
|
||||
MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));
|
||||
|
||||
errors += test(PropertyDescriptor.class, "good", true);
|
||||
PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");
|
||||
PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good",
|
||||
Test7172865.class.getMethod("getGood"),
|
||||
Test7172865.class.getMethod("setGood", args.getClass()));
|
||||
|
||||
errors += test(PropertyDescriptor.class, "bad", false);
|
||||
PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);
|
||||
PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad",
|
||||
Test7172865.class.getMethod("getBad"),
|
||||
Test7172865.class.getMethod("setBad", args.getClass()));
|
||||
|
||||
errors += test(IndexedPropertyDescriptor.class, "good", true);
|
||||
IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");
|
||||
IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good",
|
||||
Test7172865.class.getMethod("getGood"),
|
||||
Test7172865.class.getMethod("setGood", args.getClass()),
|
||||
Test7172865.class.getMethod("getGood", Integer.TYPE),
|
||||
Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));
|
||||
|
||||
errors += test(IndexedPropertyDescriptor.class, "bad", false);
|
||||
IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);
|
||||
IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad",
|
||||
Test7172865.class.getMethod("getBad"),
|
||||
Test7172865.class.getMethod("setBad", args.getClass()),
|
||||
Test7172865.class.getMethod("getBad", Integer.TYPE),
|
||||
Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));
|
||||
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
System.out.println("STEP: " + i);
|
||||
errors += test("md", null != md.getMethod());
|
||||
|
||||
errors += test("pdGoodString", pdGoodString, true, true);
|
||||
errors += test("pdGoodMethod", pdGoodMethod, true, true);
|
||||
|
||||
errors += test("pdBadString", pdBadString, true, false);
|
||||
errors += test("pdBadMethod", pdBadMethod, true, true);
|
||||
|
||||
errors += test("ipdGoodString", ipdGoodString, true, true, true, true);
|
||||
errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);
|
||||
|
||||
errors += test("ipdBadString", ipdBadString, true, false, true, false);
|
||||
errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);
|
||||
|
||||
try {
|
||||
int[] array = new int[1024];
|
||||
while (true) {
|
||||
array = new int[array.length << 1];
|
||||
}
|
||||
}
|
||||
catch (OutOfMemoryError error) {
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
throw new Error("found " + errors + " errors");
|
||||
}
|
||||
}
|
||||
|
||||
private static int test(Class<?> type, String property, boolean value) {
|
||||
String message = type.getSimpleName() + "(" + property + ") ";
|
||||
try {
|
||||
type.getConstructor(String.class, Class.class).newInstance(property, Test7172865.class);
|
||||
message += "passed";
|
||||
}
|
||||
catch (Exception exception) {
|
||||
message += "failed";
|
||||
value = !value;
|
||||
}
|
||||
if (value) {
|
||||
message += " as expected";
|
||||
}
|
||||
System.out.println(message);
|
||||
return value ? 0 : 1;
|
||||
}
|
||||
|
||||
private static int test(String message, boolean value) {
|
||||
System.out.println(message + ": " + (value ? "passed" : "failed"));
|
||||
return value ? 0 : 1;
|
||||
}
|
||||
|
||||
private static int test(String message, PropertyDescriptor pd, boolean rm, boolean wm) {
|
||||
return test(message + ".Read", rm == (null != pd.getReadMethod()))
|
||||
+ test(message + ".Write", wm == (null != pd.getWriteMethod()));
|
||||
}
|
||||
|
||||
private static int test(String message, IndexedPropertyDescriptor ipd, boolean rm, boolean wm, boolean irm, boolean iwm) {
|
||||
return test(message, ipd, rm, wm)
|
||||
+ test(message + ".IndexedRead", irm == (null != ipd.getIndexedReadMethod()))
|
||||
+ test(message + ".IndexedWrite", iwm == (null != ipd.getIndexedWriteMethod()));
|
||||
}
|
||||
|
||||
public String[] getGood() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getGood(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setGood(String[] good) {
|
||||
}
|
||||
|
||||
public void setGood(int index, String value) {
|
||||
}
|
||||
|
||||
public String[] getBad() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBad(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Test7172865 setBad(String[] bad) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Test7172865 setBad(int index, String value) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
55
test/jdk/java/beans/Introspector/Test7186794.java
Normal file
55
test/jdk/java/beans/Introspector/Test7186794.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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 7186794
|
||||
* @summary Tests setter in the super class
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Test7186794 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (null == BeanUtils.findPropertyDescriptor(MyBean.class, "value").getWriteMethod()) {
|
||||
throw new Error("The property setter is not found");
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseBean {
|
||||
|
||||
protected List<String> value;
|
||||
|
||||
public void setValue(List<String> value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean extends BaseBean {
|
||||
public List<String> getValue() {
|
||||
return super.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
test/jdk/java/beans/Introspector/Test7189112.java
Normal file
58
test/jdk/java/beans/Introspector/Test7189112.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 7189112
|
||||
* @summary Tests overridden getter
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test7189112 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (null == BeanUtils.findPropertyDescriptor(MyBean.class, "value").getWriteMethod()) {
|
||||
throw new Error("The property setter is not found");
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseBean {
|
||||
|
||||
private Object value;
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean extends BaseBean {
|
||||
@Override
|
||||
public String getValue() {
|
||||
return (String) super.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
92
test/jdk/java/beans/Introspector/Test7192955.java
Normal file
92
test/jdk/java/beans/Introspector/Test7192955.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 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 7192955 8000183
|
||||
* @summary Tests that all properties are bound
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.List;
|
||||
|
||||
public class Test7192955 {
|
||||
|
||||
public static void main(String[] args) throws IntrospectionException {
|
||||
if (!BeanUtils.findPropertyDescriptor(MyBean.class, "test").isBound()) {
|
||||
throw new Error("a simple property is not bound");
|
||||
}
|
||||
if (!BeanUtils.findPropertyDescriptor(MyBean.class, "list").isBound()) {
|
||||
throw new Error("a generic property is not bound");
|
||||
}
|
||||
if (!BeanUtils.findPropertyDescriptor(MyBean.class, "readOnly").isBound()) {
|
||||
throw new Error("a read-only property is not bound");
|
||||
}
|
||||
PropertyDescriptor[] pds = Introspector.getBeanInfo(MyBean.class, BaseBean.class).getPropertyDescriptors();
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (pd.getName().equals("test") && pd.isBound()) {
|
||||
throw new Error("a simple property is bound without superclass");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseBean {
|
||||
|
||||
private List<String> list;
|
||||
|
||||
public List<String> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public void setList(List<String> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
public List<String> getReadOnly() {
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean extends BaseBean {
|
||||
|
||||
private String test;
|
||||
|
||||
public String getTest() {
|
||||
return this.test;
|
||||
}
|
||||
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
}
|
||||
}
|
||||
159
test/jdk/java/beans/Introspector/Test7193977.java
Normal file
159
test/jdk/java/beans/Introspector/Test7193977.java
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* 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 7193977
|
||||
* @summary Tests that generified property descriptors do not loose additional info
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.awt.Image;
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Test7193977 {
|
||||
|
||||
private static final List<String> names = Arrays.asList("listType", "list", "value");
|
||||
|
||||
public static void main(String args[]) {
|
||||
for (String name : names) {
|
||||
test(Abstract.class, name);
|
||||
test(Concrete.class, name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, String name) {
|
||||
if (!Boolean.TRUE.equals(BeanUtils.getPropertyDescriptor(type, name).getValue("transient"))) {
|
||||
throw new Error("property '" + name + "' is not transient");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Concrete extends Abstract<String> {
|
||||
}
|
||||
|
||||
public static abstract class Abstract<T> {
|
||||
private List<T> list;
|
||||
|
||||
public List<T> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public T getValue(int index) {
|
||||
return (0 <= index) && (this.list != null) && (index < this.list.size())
|
||||
? this.list.get(index)
|
||||
: null;
|
||||
}
|
||||
|
||||
public void setValue(int index, T value) {
|
||||
if ((0 <= index) && (this.list != null)) {
|
||||
if (index == this.list.size()) {
|
||||
this.list.add(value);
|
||||
}
|
||||
else if (index < this.list.size()) {
|
||||
this.list.set(index, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getListType() {
|
||||
return (this.list != null)
|
||||
? this.list.getClass().getName()
|
||||
: null;
|
||||
}
|
||||
|
||||
public void setListType(String type) throws Exception {
|
||||
this.list = (type != null)
|
||||
? (List<T>) Class.forName(type).newInstance()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConcreteBeanInfo extends Wrapper {
|
||||
public ConcreteBeanInfo() throws IntrospectionException {
|
||||
super(Concrete.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class AbstractBeanInfo extends Wrapper {
|
||||
public AbstractBeanInfo() throws IntrospectionException {
|
||||
super(Abstract.class);
|
||||
for (PropertyDescriptor pd : getPropertyDescriptors()) {
|
||||
if (names.contains(pd.getName())) {
|
||||
pd.setValue("transient", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Wrapper implements BeanInfo {
|
||||
private final BeanInfo info;
|
||||
|
||||
Wrapper(Class<?> type) throws IntrospectionException {
|
||||
this.info = Introspector.getBeanInfo(type, Introspector.IGNORE_IMMEDIATE_BEANINFO);
|
||||
}
|
||||
|
||||
public BeanDescriptor getBeanDescriptor() {
|
||||
return this.info.getBeanDescriptor();
|
||||
}
|
||||
|
||||
public EventSetDescriptor[] getEventSetDescriptors() {
|
||||
return this.info.getEventSetDescriptors();
|
||||
}
|
||||
|
||||
public int getDefaultEventIndex() {
|
||||
return this.info.getDefaultEventIndex();
|
||||
}
|
||||
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
return this.info.getPropertyDescriptors();
|
||||
}
|
||||
|
||||
public int getDefaultPropertyIndex() {
|
||||
return this.info.getDefaultPropertyIndex();
|
||||
}
|
||||
|
||||
public MethodDescriptor[] getMethodDescriptors() {
|
||||
return this.info.getMethodDescriptors();
|
||||
}
|
||||
|
||||
public BeanInfo[] getAdditionalBeanInfo() {
|
||||
return this.info.getAdditionalBeanInfo();
|
||||
}
|
||||
|
||||
public Image getIcon(int kind) {
|
||||
return this.info.getIcon(kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
test/jdk/java/beans/Introspector/Test7195106.java
Normal file
68
test/jdk/java/beans/Introspector/Test7195106.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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 7195106
|
||||
* @summary Tests that explicit BeanInfo is not collected
|
||||
* @author Sergey Malenkov
|
||||
* @run main/othervm -Xmx128m Test7195106
|
||||
*/
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
|
||||
public class Test7195106 {
|
||||
|
||||
public static void main(String[] arg) throws Exception {
|
||||
BeanInfo info = Introspector.getBeanInfo(My.class);
|
||||
if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
|
||||
throw new Error("Unexpected behavior");
|
||||
}
|
||||
try {
|
||||
int[] array = new int[1024];
|
||||
while (true) {
|
||||
array = new int[array.length << 1];
|
||||
}
|
||||
}
|
||||
catch (OutOfMemoryError error) {
|
||||
System.gc();
|
||||
}
|
||||
if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
|
||||
throw new Error("Explicit BeanInfo is collected");
|
||||
}
|
||||
}
|
||||
|
||||
public static class My {
|
||||
}
|
||||
|
||||
public static class MyBeanInfo extends SimpleBeanInfo {
|
||||
@Override
|
||||
public Image getIcon(int type) {
|
||||
return new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
test/jdk/java/beans/Introspector/Test8005065.java
Normal file
131
test/jdk/java/beans/Introspector/Test8005065.java
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* 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 8005065
|
||||
* @summary Tests that all arrays in JavaBeans are guarded
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.DefaultPersistenceDelegate;
|
||||
import java.beans.Encoder;
|
||||
import java.beans.EventSetDescriptor;
|
||||
import java.beans.ExceptionListener;
|
||||
import java.beans.Expression;
|
||||
import java.beans.Statement;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.ParameterDescriptor;
|
||||
|
||||
public class Test8005065 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
testDefaultPersistenceDelegate();
|
||||
testEventSetDescriptor();
|
||||
testMethodDescriptor();
|
||||
testStatement();
|
||||
}
|
||||
|
||||
private static void testDefaultPersistenceDelegate() {
|
||||
Encoder encoder = new Encoder();
|
||||
String[] array = { "array" };
|
||||
MyDPD dpd = new MyDPD(array);
|
||||
dpd.instantiate(dpd, encoder);
|
||||
array[0] = null;
|
||||
dpd.instantiate(dpd, encoder);
|
||||
}
|
||||
|
||||
private static void testEventSetDescriptor() {
|
||||
try {
|
||||
MethodDescriptor[] array = { new MethodDescriptor(MyDPD.class.getMethod("getArray")) };
|
||||
EventSetDescriptor descriptor = new EventSetDescriptor(null, null, array, null, null);
|
||||
test(descriptor.getListenerMethodDescriptors());
|
||||
array[0] = null;
|
||||
test(descriptor.getListenerMethodDescriptors());
|
||||
descriptor.getListenerMethodDescriptors()[0] = null;
|
||||
test(descriptor.getListenerMethodDescriptors());
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testMethodDescriptor() {
|
||||
try {
|
||||
ParameterDescriptor[] array = { new ParameterDescriptor() };
|
||||
MethodDescriptor descriptor = new MethodDescriptor(MyDPD.class.getMethod("getArray"), array);
|
||||
test(descriptor.getParameterDescriptors());
|
||||
array[0] = null;
|
||||
test(descriptor.getParameterDescriptors());
|
||||
descriptor.getParameterDescriptors()[0] = null;
|
||||
test(descriptor.getParameterDescriptors());
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testStatement() {
|
||||
Object[] array = { new Object() };
|
||||
Statement statement = new Statement(null, null, array);
|
||||
test(statement.getArguments());
|
||||
array[0] = null;
|
||||
test(statement.getArguments());
|
||||
statement.getArguments()[0] = null;
|
||||
test(statement.getArguments());
|
||||
}
|
||||
|
||||
private static <T> void test(T[] array) {
|
||||
if (array.length != 1) {
|
||||
throw new Error("unexpected array length");
|
||||
}
|
||||
if (array[0] == null) {
|
||||
throw new Error("unexpected array content");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyDPD
|
||||
extends DefaultPersistenceDelegate
|
||||
implements ExceptionListener {
|
||||
|
||||
private final String[] array;
|
||||
|
||||
public MyDPD(String[] array) {
|
||||
super(array);
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public Expression instantiate(Object instance, Encoder encoder) {
|
||||
encoder.setExceptionListener(this);
|
||||
return super.instantiate(instance, encoder);
|
||||
}
|
||||
|
||||
public String[] getArray() {
|
||||
return this.array;
|
||||
}
|
||||
|
||||
public void exceptionThrown(Exception exception) {
|
||||
throw new Error("unexpected error", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
97
test/jdk/java/beans/Introspector/Test8027648.java
Normal file
97
test/jdk/java/beans/Introspector/Test8027648.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8027648
|
||||
* @summary Tests overridden getter and overloaded setter
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test8027648 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(false);
|
||||
test(true);
|
||||
}
|
||||
|
||||
private static void test(boolean indexed) {
|
||||
Class<?> parent = getPropertyType(BaseBean.class, indexed);
|
||||
Class<?> child = getPropertyType(MyBean.class, indexed);
|
||||
if (parent.equals(child) || !parent.isAssignableFrom(child)) {
|
||||
throw new Error("the child property type is not override the parent property type");
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
return ipd.getIndexedPropertyType();
|
||||
}
|
||||
return pd.getPropertyType();
|
||||
}
|
||||
|
||||
public static class BaseBean {
|
||||
private Object value;
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getIndex(int index) {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public void setIndex(int index, Object value) {
|
||||
setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean extends BaseBean {
|
||||
@Override
|
||||
public String getValue() {
|
||||
return (String) super.getValue();
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
setValue((Object) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndex(int index) {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public void setIndex(int index, String value) {
|
||||
setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/beans/Introspector/Test8027905.java
Normal file
71
test/jdk/java/beans/Introspector/Test8027905.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2024, 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.
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8027905
|
||||
* @summary Tests that GC does not affect a property type
|
||||
* @run main/othervm -Xmx16m Test8027905
|
||||
*/
|
||||
|
||||
public class Test8027905 {
|
||||
public static void main(String[] args) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(Sub.class, "foo");
|
||||
Class<?> type = pd.getPropertyType();
|
||||
|
||||
int[] array = new int[10];
|
||||
while (array != null) {
|
||||
try {
|
||||
array = new int[array.length + array.length];
|
||||
}
|
||||
catch (OutOfMemoryError error) {
|
||||
array = null;
|
||||
}
|
||||
}
|
||||
if (type != pd.getPropertyType()) {
|
||||
throw new Error("property type is changed");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Super<T> {
|
||||
public T getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(T t) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sub extends Super<String> {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFoo(String t) {
|
||||
}
|
||||
}
|
||||
}
|
||||
236
test/jdk/java/beans/Introspector/Test8034085.java
Normal file
236
test/jdk/java/beans/Introspector/Test8034085.java
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
import java.awt.Window;
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8034085
|
||||
* @summary Tests that Introspector ignores indexed getter and setter for incorrect types
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test8034085 {
|
||||
public static final StringBuilder ERROR = new StringBuilder();
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Window.class, false, true, false, false);
|
||||
|
||||
test(Bean0000.class, false, false, false, false);
|
||||
test(Bean0001.class, false, false, false, true);
|
||||
test(Bean0010.class, false, false, true, false);
|
||||
test(Bean0011.class, false, false, true, true);
|
||||
test(Bean0100.class, false, true, false, false);
|
||||
test(Bean0101.class, false, true, false, false);
|
||||
test(Bean0110.class, false, true, false, false);
|
||||
test(Bean0111.class, false, true, false, false);
|
||||
test(Bean1000.class, true, false, false, false);
|
||||
test(Bean1001.class, true, false, false, false);
|
||||
test(Bean1010.class, true, false, false, false);
|
||||
test(Bean1011.class, true, false, false, false);
|
||||
test(Bean1100.class, true, true, false, false);
|
||||
test(Bean1101.class, true, true, false, false);
|
||||
test(Bean1110.class, true, true, false, false);
|
||||
test(Bean1111.class, true, true, false, false);
|
||||
|
||||
if (0 < ERROR.length()) {
|
||||
throw new Error(ERROR.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, boolean read, boolean write, boolean readIndexed, boolean writeIndexed) {
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, "size");
|
||||
if (pd != null) {
|
||||
test(type, "read", read, null != pd.getReadMethod());
|
||||
test(type, "write", write, null != pd.getWriteMethod());
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
test(type, "indexed read", readIndexed, null != ipd.getIndexedReadMethod());
|
||||
test(type, "indexed write", writeIndexed, null != ipd.getIndexedWriteMethod());
|
||||
} else if (readIndexed || writeIndexed) {
|
||||
error(type, "indexed property does not exist");
|
||||
}
|
||||
} else if (read || write || readIndexed || writeIndexed) {
|
||||
error(type, "property does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, String name, boolean expected, boolean actual) {
|
||||
if (expected && !actual) {
|
||||
error(type, name + " method does not exist");
|
||||
} else if (!expected && actual) {
|
||||
error(type, name + " method is not expected");
|
||||
}
|
||||
}
|
||||
|
||||
private static void error(Class<?> type, String message) {
|
||||
ERROR.append("\n\t\t").append(type.getSimpleName()).append(".size: ").append(message);
|
||||
}
|
||||
|
||||
public static class Bean0000 {
|
||||
}
|
||||
|
||||
public static class Bean0001 {
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0010 {
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0011 {
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0100 {
|
||||
public void setSize(int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0101 {
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0110 {
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0111 {
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1000 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1001 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1010 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1011 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1100 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1101 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1110 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1111 {
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
233
test/jdk/java/beans/Introspector/Test8034164.java
Normal file
233
test/jdk/java/beans/Introspector/Test8034164.java
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8034164
|
||||
* @summary Tests that Introspector does not ignore indexed getter and setter for correct types
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test8034164 {
|
||||
public static final StringBuilder ERROR = new StringBuilder();
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Bean0000.class, false, false, false, false);
|
||||
test(Bean0001.class, false, false, false, true);
|
||||
test(Bean0010.class, false, false, true, false);
|
||||
test(Bean0011.class, false, false, true, true);
|
||||
test(Bean0100.class, false, true, false, false);
|
||||
test(Bean0101.class, false, true, false, true);
|
||||
test(Bean0110.class, false, true, true, false);
|
||||
test(Bean0111.class, false, true, true, true);
|
||||
test(Bean1000.class, true, false, false, false);
|
||||
test(Bean1001.class, true, false, false, true);
|
||||
test(Bean1010.class, true, false, true, false);
|
||||
test(Bean1011.class, true, false, true, true);
|
||||
test(Bean1100.class, true, true, false, false);
|
||||
test(Bean1101.class, true, true, false, true);
|
||||
test(Bean1110.class, true, true, true, false);
|
||||
test(Bean1111.class, true, true, true, true);
|
||||
|
||||
if (0 < ERROR.length()) {
|
||||
throw new Error(ERROR.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, boolean read, boolean write, boolean readIndexed, boolean writeIndexed) {
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, "size");
|
||||
if (pd != null) {
|
||||
test(type, "read", read, null != pd.getReadMethod());
|
||||
test(type, "write", write, null != pd.getWriteMethod());
|
||||
if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
test(type, "indexed read", readIndexed, null != ipd.getIndexedReadMethod());
|
||||
test(type, "indexed write", writeIndexed, null != ipd.getIndexedWriteMethod());
|
||||
} else if (readIndexed || writeIndexed) {
|
||||
error(type, "indexed property does not exist");
|
||||
}
|
||||
} else if (read || write || readIndexed || writeIndexed) {
|
||||
error(type, "property does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, String name, boolean expected, boolean actual) {
|
||||
if (expected && !actual) {
|
||||
error(type, name + " method does not exist");
|
||||
} else if (!expected && actual) {
|
||||
error(type, name + " method is not expected");
|
||||
}
|
||||
}
|
||||
|
||||
private static void error(Class<?> type, String message) {
|
||||
ERROR.append("\n\t\t").append(type.getSimpleName()).append(".size: ").append(message);
|
||||
}
|
||||
|
||||
public static class Bean0000 {
|
||||
}
|
||||
|
||||
public static class Bean0001 {
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0010 {
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0011 {
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0100 {
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0101 {
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0110 {
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean0111 {
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1000 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1001 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1010 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1011 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1100 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1101 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1110 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bean1111 {
|
||||
public int[] getSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSize(int[] value) {
|
||||
}
|
||||
|
||||
public int getSize(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSize(int index, int value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
64
test/jdk/java/beans/Introspector/Test8039776.java
Normal file
64
test/jdk/java/beans/Introspector/Test8039776.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static java.beans.Introspector.getBeanInfo;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8039776
|
||||
* @summary Tests that Introspector does not throw NPE
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test8039776 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
getBeanInfo(Base.class, Object.class);
|
||||
getBeanInfo(Child.class, Base.class);
|
||||
getBeanInfo(Child.class, Object.class);
|
||||
}
|
||||
|
||||
public static class Base {
|
||||
private SortedSet<Object> value;
|
||||
|
||||
public Set<Object> getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(SortedSet<Object> value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Child extends Base {
|
||||
public Set<Object> getValue() {
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
public void setValue(SortedSet<Object> items) {
|
||||
super.setValue(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
311
test/jdk/java/beans/Introspector/Test8040656.java
Normal file
311
test/jdk/java/beans/Introspector/Test8040656.java
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8040656
|
||||
* @summary Tests that a normal method is preferred to a synthetic one
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
public class Test8040656 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(String.class, C.class);
|
||||
test(String.class, C1.class);
|
||||
test(String.class, C2.class);
|
||||
test(String.class, C3.class);
|
||||
test(String.class, C4.class);
|
||||
test(String.class, C5.class);
|
||||
test(String.class, C6.class);
|
||||
test(String.class, C7.class);
|
||||
test(String.class, C8.class);
|
||||
test(String.class, C9.class);
|
||||
}
|
||||
|
||||
private static void test(Class<?> type, Class<?> bean) throws Exception {
|
||||
for (MethodDescriptor md : Introspector.getBeanInfo(bean).getMethodDescriptors()) {
|
||||
if (md.getName().equals("getFoo")) {
|
||||
if (type != md.getMethod().getReturnType()) {
|
||||
throw new Error("unexpected type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface A {
|
||||
public Object getFoo();
|
||||
}
|
||||
|
||||
public class C implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C1 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C2 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C3 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C4 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C5 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo5() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C6 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo5() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo6() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C7 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo5() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo6() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo7() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C8 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo5() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo6() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo7() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo8() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class C9 implements A {
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo4() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo5() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo6() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo7() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo8() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFoo9() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
84
test/jdk/java/beans/Introspector/Test8221244.java
Normal file
84
test/jdk/java/beans/Introspector/Test8221244.java
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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 8221244
|
||||
* @summary Unexpected behavior of PropertyDescription.getReadMethod for boolean properties
|
||||
*/
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
public class Test8221244 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test("bv", "isBv"); // boolean value
|
||||
test("bo", "getBo"); // Boolean object
|
||||
test("io", "getIo"); // Integer object
|
||||
}
|
||||
|
||||
private static void test(String propertyName, String expectedGetterName) {
|
||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(TestBean.class, propertyName);
|
||||
String getterName = pd.getReadMethod().getName();
|
||||
if (!getterName.equals(expectedGetterName)) {
|
||||
throw new Error("unexpected getter: " + getterName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Bean class with multiple properties (each property has "is"/"get" getters)
|
||||
*
|
||||
* For boolean properties, the "is" getter should be used
|
||||
*/
|
||||
class TestBean {
|
||||
|
||||
// boolean value
|
||||
private boolean bv;
|
||||
|
||||
public boolean isBv() {
|
||||
return bv;
|
||||
}
|
||||
|
||||
public boolean getBv() {
|
||||
return bv;
|
||||
}
|
||||
|
||||
// Boolean object
|
||||
private Boolean bo;
|
||||
public Boolean isBo() {
|
||||
return bo;
|
||||
}
|
||||
public Boolean getBo() {
|
||||
return bo;
|
||||
}
|
||||
|
||||
// Integer object
|
||||
private Integer io;
|
||||
public Integer isIo() {
|
||||
return io;
|
||||
}
|
||||
public Integer getIo() {
|
||||
return io;
|
||||
}
|
||||
}
|
||||
84
test/jdk/java/beans/Introspector/TestCacheRecursion.java
Normal file
84
test/jdk/java/beans/Introspector/TestCacheRecursion.java
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2015, 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.
|
||||
*/
|
||||
|
||||
import com.sun.beans.util.Cache;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8039137
|
||||
* @summary Tests Cache recursion
|
||||
* @author Sergey Malenkov
|
||||
* @modules java.desktop/com.sun.beans.util
|
||||
* @compile -XDignore.symbol.file TestCacheRecursion.java
|
||||
* @run main TestCacheRecursion
|
||||
*/
|
||||
|
||||
public class TestCacheRecursion {
|
||||
private static boolean ERROR;
|
||||
private static final Cache<Class<?>,Boolean> CACHE
|
||||
= new Cache<Class<?>,Boolean>(Cache.Kind.WEAK, Cache.Kind.STRONG) {
|
||||
@Override
|
||||
public Boolean create(Class<?> type) {
|
||||
if (ERROR) {
|
||||
throw new Error("not initialized");
|
||||
}
|
||||
type = type.getSuperclass();
|
||||
return (type != null) && get(type);
|
||||
}
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
CACHE.get(Z.class);
|
||||
ERROR = true;
|
||||
for (Class<?> type = Z.class; type != null; type = type.getSuperclass()) {
|
||||
CACHE.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
private class A {}
|
||||
private class B extends A {}
|
||||
private class C extends B {}
|
||||
private class D extends C {}
|
||||
private class E extends D {}
|
||||
private class F extends E {}
|
||||
private class G extends F {}
|
||||
private class H extends G {}
|
||||
private class I extends H {}
|
||||
private class J extends I {}
|
||||
private class K extends J {}
|
||||
private class L extends K {}
|
||||
private class M extends L {}
|
||||
private class N extends M {}
|
||||
private class O extends N {}
|
||||
private class P extends O {}
|
||||
private class Q extends P {}
|
||||
private class R extends Q {}
|
||||
private class S extends R {}
|
||||
private class T extends S {}
|
||||
private class U extends T {}
|
||||
private class V extends U {}
|
||||
private class W extends V {}
|
||||
private class X extends W {}
|
||||
private class Y extends X {}
|
||||
private class Z extends Y {}
|
||||
}
|
||||
143
test/jdk/java/beans/Introspector/TestMethodOrderDependence.java
Normal file
143
test/jdk/java/beans/Introspector/TestMethodOrderDependence.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8156043
|
||||
*/
|
||||
public final class TestMethodOrderDependence {
|
||||
|
||||
public static class Base {
|
||||
|
||||
public Object getI() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getE() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Super extends Base {
|
||||
|
||||
public Number getI() {
|
||||
return null;
|
||||
}
|
||||
public Comparable<?> getE() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sub extends Super {
|
||||
|
||||
public Integer getI() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFoo(Character foo) {
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Object[] foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Enum foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Long foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Long[] foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Long foo, int i) {
|
||||
}
|
||||
|
||||
public void setFoo(Object foo) {
|
||||
}
|
||||
|
||||
public void setFoo(AbstractList foo) {
|
||||
}
|
||||
|
||||
public void setFoo(ArrayList foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Integer foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Number foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Comparable<?> foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Serializable foo) {
|
||||
}
|
||||
|
||||
public void setFoo(Vector<?> foo) {
|
||||
}
|
||||
|
||||
public void setFoo(long foo) {
|
||||
}
|
||||
|
||||
public void setFoo(int foo) {
|
||||
}
|
||||
|
||||
public Enum getE() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setE(Enum e) {
|
||||
}
|
||||
|
||||
public void setE(Float e) {
|
||||
}
|
||||
|
||||
public void setE(Long e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
final BeanInfo beanInfo = Introspector.getBeanInfo(Sub.class);
|
||||
final PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
|
||||
for (final PropertyDescriptor pd : pds) {
|
||||
System.err.println("pd = " + pd);
|
||||
final Class<?> type = pd.getPropertyType();
|
||||
if (type != Class.class && type != Long[].class
|
||||
&& type != Integer.class && type != Enum.class) {
|
||||
throw new RuntimeException(Arrays.toString(pds));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
584
test/jdk/java/beans/Introspector/TestTypeResolver.java
Normal file
584
test/jdk/java/beans/Introspector/TestTypeResolver.java
Normal file
|
|
@ -0,0 +1,584 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2015, 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
|
||||
* @summary Tests com.sun.beans.TypeResolver
|
||||
* @author Eamonn McManus
|
||||
* @modules java.base/sun.reflect.generics.reflectiveObjects
|
||||
* java.desktop/com.sun.beans
|
||||
*/
|
||||
|
||||
import com.sun.beans.TypeResolver;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl;
|
||||
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
|
||||
|
||||
public class TestTypeResolver {
|
||||
static final List<Class<?>> failedCases = new ArrayList<Class<?>>();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(TestTypeResolver.class);
|
||||
if (failedCases.isEmpty())
|
||||
System.out.println("TEST PASSED");
|
||||
else {
|
||||
System.out.println("TEST FAILED: failed cases: " + failedCases);
|
||||
throw new Error("TEST FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Class<?> c) throws Exception {
|
||||
/* Every public nested class represents a test. In each case, either
|
||||
* the class contains further nested classes, in which case we
|
||||
* call this method recursively; or it declares or inherits a
|
||||
* method called getThing() and it declares a static field
|
||||
* called "expect" which
|
||||
* is the Type of that method's return value. The test consists
|
||||
* of checking that the value returned by
|
||||
* TypeResolver.resolveInClass is indeed this Type.
|
||||
*/
|
||||
System.out.println("Test " + c);
|
||||
Class<?>[] nested = c.getClasses();
|
||||
Arrays.sort(nested, classNameComparator);
|
||||
for (Class<?> n : nested)
|
||||
test(n);
|
||||
final Method m;
|
||||
try {
|
||||
m = c.getMethod("getThing");
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (nested.length == 0) {
|
||||
System.out.println(
|
||||
"TEST ERROR: class " + c.getName() + " has neither " +
|
||||
"nested classes nor getThing() method");
|
||||
failedCases.add(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Object expect = null;
|
||||
try {
|
||||
Field f = c.getDeclaredField("expect");
|
||||
expect = f.get(null);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Class<?> outer = c.getDeclaringClass();
|
||||
if (outer != null) {
|
||||
try {
|
||||
Field f = outer.getDeclaredField("expect" + c.getSimpleName());
|
||||
expect = f.get(null);
|
||||
} catch (NoSuchFieldException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (expect == null) {
|
||||
System.out.println(
|
||||
"TEST ERROR: class " + c.getName() + " has getThing() method " +
|
||||
"but not expect field");
|
||||
failedCases.add(c);
|
||||
return;
|
||||
}
|
||||
Type t = m.getGenericReturnType();
|
||||
// t = FixType.fixType(t, c);
|
||||
t = TypeResolver.resolveInClass(c, t);
|
||||
System.out.print("..." + t);
|
||||
// check expected value, and incidentally equals method defined
|
||||
// by private implementations of the various Type interfaces
|
||||
if (expect.equals(t) && t.equals(expect))
|
||||
System.out.println(", as expected");
|
||||
else if ((expect.equals(t) || t.equals(expect)) && expect.toString().equals(t.toString()))
|
||||
System.out.println(", as workaround of the 8023301 bug");
|
||||
else {
|
||||
System.out.println(" BUT SHOULD BE " + expect);
|
||||
failedCases.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ClassNameComparator implements Comparator<Class<?>> {
|
||||
public int compare(Class<?> a, Class<?> b) {
|
||||
return a.getName().compareTo(b.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<Class<?>> classNameComparator =
|
||||
new ClassNameComparator();
|
||||
|
||||
private static abstract class TypeVariableImpl<D extends GenericDeclaration>
|
||||
implements TypeVariable<D> {
|
||||
private final String name;
|
||||
private final D gd;
|
||||
private final Type[] bounds;
|
||||
|
||||
TypeVariableImpl(String name, D gd, Type... bounds) {
|
||||
this.name = name;
|
||||
this.gd = gd;
|
||||
if (bounds.length == 0)
|
||||
bounds = new Type[] {Object.class};
|
||||
this.bounds = bounds.clone();
|
||||
}
|
||||
|
||||
public Type[] getBounds() {
|
||||
return bounds.clone();
|
||||
}
|
||||
|
||||
public D getGenericDeclaration() {
|
||||
return gd;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof TypeVariable))
|
||||
return false;
|
||||
TypeVariable tv = (TypeVariable) o;
|
||||
return equal(name, tv.getName()) &&
|
||||
equal(gd, tv.getGenericDeclaration()) &&
|
||||
Arrays.equals(bounds, tv.getBounds());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hash(name) ^ hash(gd) ^ Arrays.hashCode(bounds);
|
||||
}
|
||||
|
||||
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
|
||||
return false; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T[] getAnnotations(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public Annotation[] getAnnotations() {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T[] getDeclaredAnnotations(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public Annotation[] getDeclaredAnnotations() {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public AnnotatedType[] getAnnotatedBounds() {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
|
||||
return null; // not used
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ClassTypeVariable extends TypeVariableImpl<Class<?>> {
|
||||
ClassTypeVariable(String name, Class<?> gd, Type... bounds) {
|
||||
super(name, gd, bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MethodTypeVariable extends TypeVariableImpl<Method> {
|
||||
MethodTypeVariable(String name, Method gd, Type... bounds) {
|
||||
super(name, gd, bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private static class WildcardTypeImpl implements WildcardType {
|
||||
private final Type[] upperBounds;
|
||||
private final Type[] lowerBounds;
|
||||
|
||||
WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
|
||||
if (upperBounds == null || upperBounds.length == 0)
|
||||
upperBounds = new Type[] {Object.class};
|
||||
if (lowerBounds == null)
|
||||
lowerBounds = new Type[0];
|
||||
this.upperBounds = upperBounds.clone();
|
||||
this.lowerBounds = lowerBounds.clone();
|
||||
}
|
||||
|
||||
public Type[] getUpperBounds() {
|
||||
return upperBounds.clone();
|
||||
}
|
||||
|
||||
public Type[] getLowerBounds() {
|
||||
return lowerBounds.clone();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof WildcardType) {
|
||||
WildcardType wt = (WildcardType) o;
|
||||
return Arrays.equals(upperBounds, wt.getUpperBounds()) &&
|
||||
Arrays.equals(lowerBounds, wt.getLowerBounds());
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(upperBounds) ^ Arrays.hashCode(lowerBounds);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("?");
|
||||
if (upperBounds.length > 1 || upperBounds[0] != Object.class) {
|
||||
sb.append(" extends");
|
||||
appendBounds(sb, upperBounds);
|
||||
}
|
||||
if (lowerBounds.length > 0) {
|
||||
sb.append(" super");
|
||||
appendBounds(sb, lowerBounds);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void appendBounds(StringBuilder sb, Type[] bounds) {
|
||||
boolean and = false;
|
||||
for (Type bound : bounds) {
|
||||
if (and)
|
||||
sb.append(" &");
|
||||
sb.append(" ");
|
||||
if (bound instanceof Class)
|
||||
sb.append(((Class<?>) bound).getName());
|
||||
else
|
||||
sb.append(bound);
|
||||
and = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean equal(Object x, Object y) {
|
||||
if (x == y)
|
||||
return true;
|
||||
if (x == null || y == null)
|
||||
return false;
|
||||
return x.equals(y);
|
||||
}
|
||||
|
||||
static int hash(Object x) {
|
||||
return (x == null) ? null : x.hashCode();
|
||||
}
|
||||
|
||||
|
||||
public static class Outer<T> {
|
||||
public class Inner {
|
||||
public T getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static final Type expectInner = new ClassTypeVariable("T", Outer.class);
|
||||
}
|
||||
|
||||
public static class Super<T> {
|
||||
static final Type expect = new ClassTypeVariable("T", Super.class);
|
||||
|
||||
public T getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Int extends Super<Integer> {
|
||||
static final Type expect = Integer.class;
|
||||
}
|
||||
|
||||
public static class IntOverride extends Int {
|
||||
static final Type expect = Integer.class;
|
||||
|
||||
public Integer getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Mid<X> extends Super<X> {
|
||||
static final Type expect = new ClassTypeVariable("X", Mid.class);
|
||||
}
|
||||
|
||||
public static class Str extends Mid<String> {
|
||||
static final Type expect = String.class;
|
||||
}
|
||||
|
||||
public static class ListInt extends Super<List<Integer>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {Integer.class}, null);
|
||||
}
|
||||
|
||||
public static class ListIntSub extends ListInt {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {Integer.class}, null);
|
||||
|
||||
public List<Integer> getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListU<U> extends Super<List<U>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {new ClassTypeVariable("U", ListU.class)}, null);
|
||||
}
|
||||
|
||||
public static class ListUInt extends ListU<Integer> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {Integer.class}, null);
|
||||
}
|
||||
|
||||
public static class ListUSub<V> extends ListU<V> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {new ClassTypeVariable("V", ListUSub.class)}, null);
|
||||
|
||||
public List<V> getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListUSubInt extends ListUSub<Integer> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {Integer.class}, null);
|
||||
}
|
||||
|
||||
public static class TwoParams<S, T> extends Super<S> {
|
||||
static final Type expect = new ClassTypeVariable("S", TwoParams.class);
|
||||
}
|
||||
|
||||
public static class TwoParamsSub<T> extends TwoParams<T, Integer> {
|
||||
static final Type expect = new ClassTypeVariable("T", TwoParamsSub.class);
|
||||
}
|
||||
|
||||
public static class TwoParamsSubSub extends TwoParamsSub<String> {
|
||||
static final Type expect = String.class;
|
||||
}
|
||||
|
||||
public static interface Intf<T> {
|
||||
static final Type expect = new ClassTypeVariable("T", Intf.class);
|
||||
|
||||
public T getThing();
|
||||
}
|
||||
|
||||
public static abstract class Impl implements Intf<String> {
|
||||
static final Type expect = String.class;
|
||||
}
|
||||
|
||||
public static class Impl2 extends Super<String> implements Intf<String> {
|
||||
static final Type expect = String.class;
|
||||
}
|
||||
|
||||
public static class Bound<T extends Number> extends Super<T> {
|
||||
static final Type expect = new ClassTypeVariable("T", Bound.class, Number.class);
|
||||
}
|
||||
|
||||
public static class BoundInt extends Bound<Integer> {
|
||||
static final Type expect = Integer.class;
|
||||
}
|
||||
|
||||
public static class RawBound extends Bound {
|
||||
static final Type expect = Number.class;
|
||||
}
|
||||
|
||||
public static class RawBoundInt extends BoundInt {
|
||||
static final Type expect = Integer.class;
|
||||
}
|
||||
|
||||
public static class MethodParam<T> {
|
||||
private static final Method m;
|
||||
|
||||
static {
|
||||
try {
|
||||
m = MethodParam.class.getMethod("getThing");
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
static final Type expect = new MethodTypeVariable("T", m);
|
||||
|
||||
public <T> T getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Raw extends Super {
|
||||
static final Type expect = Object.class;
|
||||
}
|
||||
|
||||
public static class RawSub extends Raw {
|
||||
static final Type expect = Object.class;
|
||||
}
|
||||
|
||||
public static class SimpleArray extends Super<String[]> {
|
||||
static final Type expect = String[].class;
|
||||
}
|
||||
|
||||
public static class GenericArray extends Super<List<String>[]> {
|
||||
static final Type expect = GenericArrayTypeImpl.make(
|
||||
ParameterizedTypeImpl.make(List.class, new Type[] {String.class}, null));
|
||||
}
|
||||
|
||||
public static class GenericArrayT<T> extends Super<T[]> {
|
||||
static final Type expect = GenericArrayTypeImpl.make(
|
||||
new ClassTypeVariable("T", GenericArrayT.class));
|
||||
}
|
||||
|
||||
public static class GenericArrayTSub extends GenericArrayT<String[]> {
|
||||
static final Type expect = String[][].class;
|
||||
}
|
||||
|
||||
public static class Wildcard extends Super<List<?>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class, new Type[] {new WildcardTypeImpl(null, null)}, null);
|
||||
}
|
||||
|
||||
public static class WildcardT<T> extends Super<List<? extends T>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
new WildcardTypeImpl(
|
||||
new Type[] {new ClassTypeVariable("T", WildcardT.class)},
|
||||
null)},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class WildcardTSub extends WildcardT<Integer> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
new WildcardTypeImpl(
|
||||
new Type[] {Integer.class},
|
||||
null)},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class WildcardTSubSub<X> extends WildcardTSub {
|
||||
// X is just so we can have a raw subclass
|
||||
static final Type expect = WildcardTSub.expect;
|
||||
}
|
||||
|
||||
public static class RawWildcardTSubSub extends WildcardTSubSub {
|
||||
static final Type expect = List.class;
|
||||
}
|
||||
|
||||
public static class WildcardTSuper<T> extends Super<List<? super T>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
new WildcardTypeImpl(
|
||||
null,
|
||||
new Type[] {new ClassTypeVariable("T", WildcardTSuper.class)})},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class WildcardTSuperSub extends WildcardTSuper<Integer> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
new WildcardTypeImpl(
|
||||
null,
|
||||
new Type[] {Integer.class})},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class SuperMap<K, V> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
Map.class,
|
||||
new Type[] {
|
||||
new ClassTypeVariable("K", SuperMap.class),
|
||||
new ClassTypeVariable("V", SuperMap.class)},
|
||||
null);
|
||||
|
||||
public Map<K, V> getThing() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubMap extends SuperMap<String, Integer> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
Map.class,
|
||||
new Type[] {String.class, Integer.class},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class ListListT<T> extends Super<List<List<T>>> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {new ClassTypeVariable("T", ListListT.class)},
|
||||
null)},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class ListListString extends ListListT<String> {
|
||||
static final Type expect = ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {
|
||||
ParameterizedTypeImpl.make(
|
||||
List.class,
|
||||
new Type[] {String.class},
|
||||
null)},
|
||||
null);
|
||||
}
|
||||
|
||||
public static class UExtendsT<T, U extends T> extends Super<U> {
|
||||
static final Type expect = new ClassTypeVariable(
|
||||
"U", UExtendsT.class, new ClassTypeVariable("T", UExtendsT.class));
|
||||
}
|
||||
|
||||
public static class UExtendsTSub extends UExtendsT<Number, Integer> {
|
||||
static final Type expect = Integer.class;
|
||||
}
|
||||
|
||||
public static class SelfRef<T extends SelfRef<T>> extends Super<T> {
|
||||
static final Type expect =
|
||||
SelfRef.class.getTypeParameters()[0];
|
||||
}
|
||||
|
||||
public static class SelfRefSub extends SelfRef<SelfRefSub> {
|
||||
static final Type expect = SelfRefSub.class;
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/beans/Introspector/memory/Bean.java
Normal file
71
test/jdk/java/beans/Introspector/memory/Bean.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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.
|
||||
*/
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class Bean {
|
||||
private String name;
|
||||
private int number;
|
||||
private ActionListener listener;
|
||||
|
||||
public Bean() {
|
||||
this("Bean", 1);
|
||||
}
|
||||
|
||||
public Bean(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(int i) {
|
||||
this.number = i;
|
||||
}
|
||||
|
||||
// Introduce at least one Eventset
|
||||
|
||||
public void addActionListener(ActionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
this.listener = null;
|
||||
}
|
||||
|
||||
public ActionListener[] getActionListeners() {
|
||||
return (this.listener != null)
|
||||
? new ActionListener[] {this.listener}
|
||||
: new ActionListener[] {};
|
||||
}
|
||||
}
|
||||
52
test/jdk/java/beans/Introspector/memory/Bean2.java
Normal file
52
test/jdk/java/beans/Introspector/memory/Bean2.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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.
|
||||
*/
|
||||
|
||||
public class Bean2 {
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
public Bean2() {
|
||||
this("Bean2", 1);
|
||||
}
|
||||
|
||||
public Bean2(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(int i) {
|
||||
this.number = i;
|
||||
}
|
||||
}
|
||||
52
test/jdk/java/beans/Introspector/memory/Bean3.java
Normal file
52
test/jdk/java/beans/Introspector/memory/Bean3.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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.
|
||||
*/
|
||||
|
||||
public class Bean3 {
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
public Bean3() {
|
||||
this("Bean3", 1);
|
||||
}
|
||||
|
||||
public Bean3(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(int i) {
|
||||
this.number = i;
|
||||
}
|
||||
}
|
||||
52
test/jdk/java/beans/Introspector/memory/Bean4.java
Normal file
52
test/jdk/java/beans/Introspector/memory/Bean4.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, 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.
|
||||
*/
|
||||
|
||||
public class Bean4 {
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
public Bean4() {
|
||||
this("Bean4", 1);
|
||||
}
|
||||
|
||||
public Bean4(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public void setNumber(int i) {
|
||||
this.number = i;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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.
|
||||
*/
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
|
||||
class SimpleClassLoader extends ClassLoader {
|
||||
public static int numFinalizers;
|
||||
|
||||
SimpleClassLoader() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
protected Class findClass(String name) throws ClassNotFoundException {
|
||||
File f = new File(System.getProperty("test.classes"), name + ".class");
|
||||
InputStream fi = null;
|
||||
try {
|
||||
fi = new FileInputStream(f);
|
||||
int length = fi.available();
|
||||
byte[] bytes = new byte[length];
|
||||
fi.read(bytes, 0, length);
|
||||
return defineClass(name, bytes, 0, length);
|
||||
}
|
||||
catch (IOException exception) {
|
||||
// we could not find the class, so indicate the problem
|
||||
throw new ClassNotFoundException(name, exception);
|
||||
}
|
||||
finally {
|
||||
if (null != fi) {
|
||||
try {
|
||||
fi.close();
|
||||
} catch (IOException exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
numFinalizers++;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue