8079084: Behavior of BeanProperty.enumerationValues() contradicts spec
authorserb
Tue, 02 Jun 2015 19:27:06 +0300
changeset 31162 b4c9194f282c
parent 31161 a93cd7e29b8c
child 31163 8a4b47348c84
8079084: Behavior of BeanProperty.enumerationValues() contradicts spec Reviewed-by: alexsch, malenkov
jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java
jdk/test/java/beans/Introspector/4058433/TestBeanProperty.java
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java	Mon Jun 01 17:46:28 2015 +0400
+++ b/jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java	Tue Jun 02 19:27:06 2015 +0300
@@ -125,38 +125,36 @@
                 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);
+                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;
                             }
-                            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) {
-                            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();
                 }
             }
         }
--- a/jdk/test/java/beans/Introspector/4058433/TestBeanProperty.java	Mon Jun 01 17:46:28 2015 +0400
+++ b/jdk/test/java/beans/Introspector/4058433/TestBeanProperty.java	Tue Jun 02 19:27:06 2015 +0300
@@ -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 @@
  */
 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 @@
                 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 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;