8079084: Behavior of BeanProperty.enumerationValues() contradicts spec
Reviewed-by: alexsch, malenkov
This commit is contained in:
parent
435c40f71b
commit
6a907dfc02
@ -125,38 +125,36 @@ public final class PropertyInfo {
|
|||||||
put(Name.visualUpdate, annotation.visualUpdate());
|
put(Name.visualUpdate, annotation.visualUpdate());
|
||||||
put(Name.description, annotation.description());
|
put(Name.description, annotation.description());
|
||||||
String[] values = annotation.enumerationValues();
|
String[] values = annotation.enumerationValues();
|
||||||
if (0 < values.length) {
|
try {
|
||||||
try {
|
Object[] array = new Object[3 * values.length];
|
||||||
Object[] array = new Object[3 * values.length];
|
int index = 0;
|
||||||
int index = 0;
|
for (String value : values) {
|
||||||
for (String value : values) {
|
Class<?> type = info.method.getDeclaringClass();
|
||||||
Class<?> type = info.method.getDeclaringClass();
|
String name = value;
|
||||||
String name = value;
|
int pos = value.lastIndexOf('.');
|
||||||
int pos = value.lastIndexOf('.');
|
if (pos > 0) {
|
||||||
if (pos > 0) {
|
name = value.substring(0, pos);
|
||||||
name = value.substring(0, pos);
|
if (name.indexOf('.') < 0) {
|
||||||
if (name.indexOf('.') < 0) {
|
String pkg = type.getName();
|
||||||
String pkg = type.getName();
|
name = pkg.substring(0, 1 + Math.max(
|
||||||
name = pkg.substring(0, 1 + Math.max(
|
pkg.lastIndexOf('.'),
|
||||||
pkg.lastIndexOf('.'),
|
pkg.lastIndexOf('$'))) + name;
|
||||||
pkg.lastIndexOf('$'))) + name;
|
|
||||||
}
|
|
||||||
type = findClass(name);
|
|
||||||
name = value.substring(pos + 1);
|
|
||||||
}
|
|
||||||
Field field = type.getField(name);
|
|
||||||
if (Modifier.isStatic(field.getModifiers()) && info.type.isAssignableFrom(field.getType())) {
|
|
||||||
array[index++] = name;
|
|
||||||
array[index++] = field.get(null);
|
|
||||||
array[index++] = value;
|
|
||||||
}
|
}
|
||||||
|
type = findClass(name);
|
||||||
|
name = value.substring(pos + 1);
|
||||||
}
|
}
|
||||||
if (index == array.length) {
|
Field field = type.getField(name);
|
||||||
put(Name.enumerationValues, array);
|
if (Modifier.isStatic(field.getModifiers()) && info.type.isAssignableFrom(field.getType())) {
|
||||||
|
array[index++] = name;
|
||||||
|
array[index++] = field.get(null);
|
||||||
|
array[index++] = value;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
|
||||||
ignored.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
if (index == array.length) {
|
||||||
|
put(Name.enumerationValues, array);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -20,12 +20,14 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.beans.BeanProperty;
|
import java.beans.BeanProperty;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyChangeSupport;
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
/*
|
|
||||||
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4058433
|
* @bug 4058433
|
||||||
* @summary Tests the BeanProperty annotation
|
* @summary Tests the BeanProperty annotation
|
||||||
@ -34,7 +36,10 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
public class TestBeanProperty {
|
public class TestBeanProperty {
|
||||||
public static void main(String[] args) throws Exception {
|
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, EV.class, EVL.class, EVX.class};
|
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};
|
||||||
for (Class<?> type : types) {
|
for (Class<?> type : types) {
|
||||||
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
|
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
|
||||||
if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
|
if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
|
||||||
@ -77,6 +82,14 @@ public class TestBeanProperty {
|
|||||||
BeanUtils.reportPropertyDescriptor(pd);
|
BeanUtils.reportPropertyDescriptor(pd);
|
||||||
throw new Error("enumerationValues from another package");
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +232,34 @@ public class TestBeanProperty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
public static class EV {
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user