8079084: Behavior of BeanProperty.enumerationValues() contradicts spec

Reviewed-by: alexsch, malenkov
This commit is contained in:
Sergey Bylokhov 2015-06-02 19:27:06 +03:00
parent 435c40f71b
commit 6a907dfc02
2 changed files with 70 additions and 31 deletions

View File

@ -125,38 +125,36 @@ public final class PropertyInfo {
put(Name.visualUpdate, annotation.visualUpdate());
put(Name.description, annotation.description());
String[] values = annotation.enumerationValues();
if (0 < values.length) {
try {
Object[] array = new Object[3 * values.length];
int index = 0;
for (String value : values) {
Class<?> type = info.method.getDeclaringClass();
String name = value;
int pos = value.lastIndexOf('.');
if (pos > 0) {
name = value.substring(0, pos);
if (name.indexOf('.') < 0) {
String pkg = type.getName();
name = pkg.substring(0, 1 + Math.max(
pkg.lastIndexOf('.'),
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;
try {
Object[] array = new Object[3 * values.length];
int index = 0;
for (String value : values) {
Class<?> type = info.method.getDeclaringClass();
String name = value;
int pos = value.lastIndexOf('.');
if (pos > 0) {
name = value.substring(0, pos);
if (name.indexOf('.') < 0) {
String pkg = type.getName();
name = pkg.substring(0, 1 + Math.max(
pkg.lastIndexOf('.'),
pkg.lastIndexOf('$'))) + name;
}
type = findClass(name);
name = value.substring(pos + 1);
}
if (index == array.length) {
put(Name.enumerationValues, array);
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;
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
if (index == array.length) {
put(Name.enumerationValues, array);
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}

View File

@ -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.
*
* 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
* 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
@ -34,7 +36,10 @@ import java.util.Arrays;
*/
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, 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) {
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
@ -77,6 +82,14 @@ public class TestBeanProperty {
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"));
}
}
}
@ -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 {
private int value;