test/jdk/java/beans/Introspector/Test4168833.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 5506
diff changeset
    26
 * @bug 4168833 8034085
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests that Introspector does not create IndexedPropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          from non-indexed PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Mark Davidson
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 5506
diff changeset
    30
 * @author Sergey Malenkov
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.IndexedPropertyDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The base class "color" property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * creates both an IndexedPropertyDescriptor which has a conflicting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * type for getColor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class Test4168833 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        // When the Sub class is introspected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        // the property type should be color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // The complete "classic" set of properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        // has been completed accross the hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        test(Sub.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        test(Sub2.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static void test(Class type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        if (pd instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            error(pd, type.getSimpleName() + ".prop should not be an indexed property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (!pd.getPropertyType().equals(Color.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            error(pd, type.getSimpleName() + ".prop type should be a Color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (null == pd.getReadMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            error(pd, type.getSimpleName() + ".prop should have classic read method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (null == pd.getWriteMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            error(pd, type.getSimpleName() + ".prop should have classic write method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static void error(PropertyDescriptor pd, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        BeanUtils.reportPropertyDescriptor(pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        throw new Error(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static class Base {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public Color getProp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        public Dimension getProp(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static class Sub extends Base {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        public void setProp(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static class Base2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        public void setProp(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        public void setProp(int i, Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static class Sub2 extends Base2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        public Color getProp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}