1 /*
2  * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 4653179
27  * @summary Tests string equality for Statement and Expression
28  * @author Mark Davidson
29  */
30 
31 import java.beans.Expression;
32 import javax.swing.JButton;
33 
34 public class Test4653179 {
main(String[] args)35     public static void main(String[] args) throws Exception {
36         String [] array = {"first string", "second one"};
37 
38         Object valueInt = testInt(array, "get", 0);
39         if (!valueInt.equals(array[0]))
40             throw new Error("unexpected value: " + valueInt);
41 
42         Object valueNew = testNew(array, "get", 1);
43         if (!valueNew.equals(array[1]))
44             throw new Error("unexpected value: " + valueNew);
45 
46 
47         valueInt = testInt(Class.class, "forName", "javax.swing.JButton");
48         if (!valueInt.equals(JButton.class))
49             throw new Error("unexpected value: " + valueInt);
50 
51         valueNew = testNew(Class.class, "forName", "javax.swing.JButton");
52         if (!valueNew.equals(JButton.class))
53             throw new Error("unexpected value: " + valueNew);
54 
55 
56         testInt(JButton.class, "new");
57         testNew(JButton.class, "new");
58     }
59 
testInt(Object target, String name, Object... args)60     private static Object testInt(Object target, String name, Object... args) throws Exception {
61         return new Expression(target, name, args).getValue();
62     }
63 
testNew(Object target, String name, Object... args)64     private static Object testNew(Object target, String name, Object... args) throws Exception {
65         return testInt(target, new String(name), args); // non-intern string
66     }
67 }
68