< prev index next >

test/java/beans/Introspector/BeanPropertyTest.java

Print this page

        

@@ -295,15 +295,11 @@
             hidden       = HIDDEN,
             preferred    = PREFERRED,
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
-        public int getX(int i) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            return x[i];
-        }
+        public int getX(int i) { return x[i]; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 

@@ -320,15 +316,11 @@
             hidden       = HIDDEN,
             preferred    = PREFERRED,
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
-        public void setX(int i, int v) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            x[i] = v;
-        }
+        public void setX(int i, int v) { x[i] = v; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 

@@ -346,15 +338,11 @@
             hidden       = HIDDEN,
             preferred    = PREFERRED,
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
-        public int getX(int i) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            return x[i];
-        }
+        public int getX(int i) { return x[i]; }
 
         public int[] getX() { return x; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}

@@ -374,15 +362,11 @@
             hidden       = HIDDEN,
             preferred    = PREFERRED,
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
-        public void setX(int i, int v) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            x[i] = v;
-        }
+        public void setX(int i, int v) { x[i] = v; }
 
         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}

@@ -405,15 +389,11 @@
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
         public int[] getX() { return x; }
 
-        public int getX(int i) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            return x[i];
-        }
+        public int getX(int i) { return x[i]; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 

@@ -434,15 +414,11 @@
             required     = REQUIRED,
             visualUpdate = UPDATE,
             enumerationValues = {V_NAME})
         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 
-        public void setX(int i, int v) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            x[i] = v;
-        }
+        public void setX(int i, int v) { x[i] = v; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 

@@ -470,15 +446,11 @@
             expert       = !EXPERT,
             hidden       = !HIDDEN,
             preferred    = !PREFERRED,
             required     = !REQUIRED,
             visualUpdate = !UPDATE)
-        public int getX(int i) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            return x[i];
-        }
+        public int getX(int i) { return x[i]; }
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 

@@ -506,15 +478,11 @@
             expert       = !EXPERT,
             hidden       = !HIDDEN,
             preferred    = !PREFERRED,
             required     = !REQUIRED,
             visualUpdate = !UPDATE)
-        public void setX(int i, int v) throws IndexOutOfBoundsException {
-            if (i < 0 || i >= x.length) {
-                throw new IndexOutOfBoundsException(); }
-            x[i] = v;
-        }
+        public void setX(int i, int v) { x[i] = v; }
 
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }

@@ -835,11 +803,57 @@
 
         public void addPropertyChangeListener(PropertyChangeListener l)    {}
         public void removePropertyChangeListener(PropertyChangeListener l) {}
     }
 
+    public static class Self {
+
+        private final static String TESTCASE = "trivial singleton";
 
+        private static Self instance = null;
+        private Self() {}
+
+        @BeanProperty(
+            description  = DESCRIPTION,
+            bound        = BOUND,
+            expert       = EXPERT,
+            hidden       = HIDDEN,
+            preferred    = PREFERRED,
+            required     = REQUIRED,
+            visualUpdate = UPDATE)
+        public Self getSelf() {
+            if (instance == null) { instance = new Self(); }
+            return instance;
+        }
+
+        public void addPropertyChangeListener(PropertyChangeListener l)    {}
+        public void removePropertyChangeListener(PropertyChangeListener l) {}
+    }
+
+    public static class SelfArr {
+
+        private final static String TESTCASE = "trivial singleton + array";
+
+        private static SelfArr arr[] = null;
+        private SelfArr() {}
+
+        @BeanProperty(
+            description  = DESCRIPTION,
+            bound        = BOUND,
+            expert       = EXPERT,
+            hidden       = HIDDEN,
+            preferred    = PREFERRED,
+            required     = REQUIRED,
+            visualUpdate = UPDATE)
+        public SelfArr[] getSelfArr() {
+            if (arr == null) { arr = new SelfArr[]{new SelfArr(), new SelfArr()}; }
+            return arr;
+        }
+
+        public void addPropertyChangeListener(PropertyChangeListener l)    {}
+        public void removePropertyChangeListener(PropertyChangeListener l) {}
+    }
 
 
     // ---------- checks ----------
 
     private static boolean check(String what, boolean v, boolean ref) {

@@ -848,11 +862,11 @@
         if (!ok) { System.out.println(
             "invalid " + what + ": " + v + ", expected: " + ref); }
         return ok;
     }
 
-    private static boolean checkInfo(BeanInfo i) {
+    private static boolean checkInfo(BeanInfo i, boolean checkVals) {
 
         System.out.println("checking info...");
 
         PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
         int nd = descriptors.length;

@@ -874,10 +888,12 @@
         ok &= check("isPreferred", d.isPreferred(), PREFERRED);
         ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
         ok &= check("visualUpdate",
             (boolean) d.getValue("visualUpdate"), UPDATE);
 
+        if (!checkVals) { return ok; }
+
         Object vals[] = (Object[]) d.getValue("enumerationValues");
         if (vals == null) {
             System.out.println("null enumerationValues");
             return false;
         }

@@ -934,10 +950,14 @@
             c.equals(G09.class) ||
             c.equals(S09.class) ||
             c.equals(GS.class));
     }
 
+    private static boolean ignoreVals(Class<?> c) {
+        return (c.equals(Self.class) || c.equals(SelfArr.class));
+    }
+
 
     // ---------- run test ----------
 
     public static void main(String[] args) throws Exception {
 

@@ -957,11 +977,12 @@
             // G12.class, S12.class, // TODO: please update after 8132163 fix
             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
-            getX.class, setX.class
+            getX.class, setX.class,
+            Self.class, SelfArr.class
         };
 
         boolean passed = true;
 
         for (Class<?> c: cases) {

@@ -972,11 +993,11 @@
 
             System.out.println("\n" + c.getSimpleName() + " (" + descr + "):");
             BeanInfo i;
             try { i = Introspector.getBeanInfo(c, Object.class); }
             catch (IntrospectionException e) { throw new RuntimeException(e); }
-            boolean ok = checkInfo(i);
+            boolean ok = checkInfo(i, !ignoreVals(c));
             if (checkAlternative(c)) {
                 ok |= checkAlternativeInfo(i);
             }
             System.out.println(ok ? "OK" : "NOK");
             passed = passed && ok;
< prev index next >