jdk/test/java/beans/VetoableChangeSupport/Test7148143.java
author lana
Tue, 23 May 2017 21:11:42 +0000
changeset 45187 331a6542b5b8
parent 12032 49ac5a2b1d5c
permissions -rw-r--r--
Added tag jdk-10+7 for changeset d554736d963e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12032
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     1
/*
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     4
 *
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     8
 *
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    13
 * accompanied this code).
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    14
 *
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    18
 *
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    21
 * questions.
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    22
 */
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    23
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    24
/*
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    25
 * @test
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    26
 * @bug 7148143
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    27
 * @summary Tests ClassCastException for the VetoableChangeSupport class
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    28
 * @author Sergey Malenkov
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    29
 */
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    30
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    31
import java.beans.PropertyChangeEvent;
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    32
import java.beans.VetoableChangeListener;
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    33
import java.beans.VetoableChangeSupport;
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    34
import java.util.EventListener;
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    35
import java.util.EventListenerProxy;
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    36
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    37
public class Test7148143 {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    38
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    39
    private static class CustomProxy
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    40
            extends EventListenerProxy<EventListener>
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    41
            implements VetoableChangeListener {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    42
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    43
        public CustomProxy() {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    44
            super(new EventListener() {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    45
            });
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    46
        }
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    47
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    48
        public void vetoableChange(PropertyChangeEvent event) {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    49
        }
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    50
    }
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    51
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    52
    public static void main(String[] args) {
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    53
        VetoableChangeListener listener = new CustomProxy();
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    54
        VetoableChangeSupport support = new VetoableChangeSupport(listener);
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    55
        support.addVetoableChangeListener(listener);
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    56
        support.addVetoableChangeListener("foo", listener); // cast class exception
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    57
    }
49ac5a2b1d5c 7148143: PropertyChangeSupport.addPropertyChangeListener can throw ClassCastException
malenkov
parents:
diff changeset
    58
}