8132973: @BeanProperty: what is the correct output in case of repeating annotations?
authorserb
Thu, 26 May 2016 16:12:12 +0300
changeset 39003 597412b25729
parent 39002 5538b16a27af
child 39004 509853dd7d6c
8132973: @BeanProperty: what is the correct output in case of repeating annotations? Reviewed-by: alexsch, avstepan
jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java
jdk/src/java.desktop/share/classes/java/beans/BeanProperty.java
jdk/test/java/beans/Introspector/AnonymousClassBeanPropertyTest.java
jdk/test/java/beans/Introspector/BeanPropertyTest.java
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java	Thu May 26 17:01:24 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java	Thu May 26 16:12:12 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -22,6 +22,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package com.sun.beans.introspect;
 
 import java.beans.BeanProperty;
@@ -40,7 +41,11 @@
 import static com.sun.beans.finder.ClassFinder.findClass;
 
 public final class PropertyInfo {
-    public enum Name {bound, expert, hidden, preferred, required, visualUpdate, description, enumerationValues}
+
+    public enum Name {
+        bound, expert, hidden, preferred, required, visualUpdate, description,
+        enumerationValues
+    }
 
     private static final String VETO_EXCEPTION_NAME = "java.beans.PropertyVetoException";
     private static final Class<?> VETO_EXCEPTION;
@@ -107,12 +112,14 @@
         if ((this.type == null) && (this.indexed == null)) {
             return false;
         }
-        initialize(this.write);
-        initialize(this.read);
+        boolean done = initialize(this.read);
+        if (!done) {
+            initialize(this.write);
+        }
         return true;
     }
 
-    private void initialize(MethodInfo info) {
+    private boolean initialize(MethodInfo info) {
         if (info != null) {
             BeanProperty annotation = info.method.getAnnotation(BeanProperty.class);
             if (annotation != null) {
@@ -157,8 +164,10 @@
                 } catch (Exception ignored) {
                     ignored.printStackTrace();
                 }
+                return true;
             }
         }
+        return false;
     }
 
     public Class<?> getPropertyType() {
--- a/jdk/src/java.desktop/share/classes/java/beans/BeanProperty.java	Thu May 26 17:01:24 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/beans/BeanProperty.java	Thu May 26 16:12:12 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -22,6 +22,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package java.beans;
 
 import java.lang.annotation.Documented;
@@ -32,16 +33,16 @@
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 /**
- * An annotation used to specify some property-related information
- * for the automatically generated {@link BeanInfo} classes.
- * This annotation is not used if the annotated class
- * has a corresponding user-defined {@code BeanInfo} class,
- * which does not imply the automatic analysis.
+ * An annotation used to specify some property-related information for the
+ * automatically generated {@link BeanInfo} classes. This annotation is not used
+ * if the annotated class has a corresponding user-defined {@code BeanInfo}
+ * class, which does not imply the automatic analysis. If both the read and the
+ * write methods of the property are annotated, then the read method annotation
+ * will have more priority and replace the write method annotation.
  *
+ * @author Sergey A. Malenkov
  * @see BeanInfo#getPropertyDescriptors
  * @since 9
- *
- * @author Sergey A. Malenkov
  */
 @Documented
 @Target({METHOD})
--- a/jdk/test/java/beans/Introspector/AnonymousClassBeanPropertyTest.java	Thu May 26 17:01:24 2016 +0530
+++ b/jdk/test/java/beans/Introspector/AnonymousClassBeanPropertyTest.java	Thu May 26 16:12:12 2016 +0300
@@ -38,8 +38,7 @@
  * @author a.stepanov
  * @run main AnonymousClassBeanPropertyTest
  */
-
-
+//TODO in final revision each test should have only one checkInfo/checkAlternate
 public class AnonymousClassBeanPropertyTest {
 
     private final static String  DESCRIPTION = "TEST";
@@ -655,8 +654,6 @@
         System.out.println("OK = " + ok);
         passed = passed && ok;
 
-        // TODO: please uncomment/update after 8132973 fix
-        /*
         IGetSet testGetSet_3 = new IGetSet() {
 
             private double x;
@@ -688,10 +685,7 @@
         };
         ok = checkInfo(testGetSet_3.getClass(), "IGetSet-3", true);
         System.out.println("OK = " + ok);
-        ok2 = checkAlternativeInfo(testGetSet_3.getClass(), "IGetSet-3");
-        System.out.println("OK = " + ok2);
-        passed = passed && (ok || ok2);
-        */
+        passed = passed && ok;
 
         //----------------------------------------------------------------------
 
@@ -746,8 +740,6 @@
         System.out.println("OK = " + ok);
         passed = passed && ok;
 
-        // TODO: please uncomment/update after 8132973 fix
-        /*
         IGetSetByIndex testGetSetByIndex_3 = new IGetSetByIndex() {
 
             private double x[] = {X, X};
@@ -783,11 +775,7 @@
         };
         ok = checkInfo(testGetSetByIndex_3.getClass(), "IGetSetByIndex-3", true);
         System.out.println("OK = " + ok);
-        ok2 = checkAlternativeInfo(
-            testGetSetByIndex_3.getClass(), "IGetSetByIndex-3");
-        System.out.println("OK = " + ok2);
-        passed = passed && (ok || ok2);
-        */
+        passed = passed && ok;
 
         //----------------------------------------------------------------------
 
@@ -855,7 +843,7 @@
         passed = passed && ok;
         */
 
-        // TODO: please uncomment/update after 8132973 fix
+        // TODO: please uncomment/update after 8155013 fix
         /*
         IGetSetBoth testGetSetBoth_3 = new IGetSetBoth() {
 
@@ -978,8 +966,6 @@
         System.out.println("OK = " + ok2);
         passed = passed && (ok || ok2);
 
-        // TODO: please uncomment/update after 8132973 fix
-        /*
         IIs testIs_4 = new IIs() {
 
             private boolean b;
@@ -1010,11 +996,7 @@
         };
         ok = checkInfo(testIs_4.getClass(), "IIs-4", false);
         System.out.println("OK = " + ok);
-        ok2 = checkAlternativeInfo(testIs_4.getClass(), "IIs-4");
-        System.out.println("OK = " + ok2);
-        passed = passed && (ok || ok2);
-        */
-
+        passed = passed && ok;
 
         //----------------------------------------------------------------------
 
--- a/jdk/test/java/beans/Introspector/BeanPropertyTest.java	Thu May 26 17:01:24 2016 +0530
+++ b/jdk/test/java/beans/Introspector/BeanPropertyTest.java	Thu May 26 16:12:12 2016 +0300
@@ -1033,7 +1033,7 @@
             G13.class, // S13.class, // TODO: please update after 8154756 fix
             // G14.class, S14.class, // TODO: please update after 8132888 fix or
                                      // remove these cases if it is not an issue
-            // GS.class, // TODO: please update after 8132973 fix
+            GS.class,
             getX.class, setX.class,
             Self.class, SelfArr.class
         };