1 /*
2  * Copyright (c) 2003, 2016, 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 import javax.sound.sampled.CompoundControl;
25 import javax.sound.sampled.Control;
26 
27 /**
28  * @test
29  * @bug 4629190
30  * @summary CompoundControl: getMemberControls() and toString() throw
31  *          NullPointerException
32  */
33 public class ToString {
main(String args[])34     public static void main(String args[]) throws Exception {
35         System.out.println();
36         System.out.println();
37         System.out.println("4629190: CompoundControl: getMemberControls() and toString() throw NullPointerException");
38 
39         String firstControlTypeName = "first_Control_Type_Name";
40         String secondControlTypeName = "second_Control_Type_Name";
41         String thirdControlTypeName = "third_Control_Type_Name";
42 
43         Control.Type firstControlType = new TestControlType(firstControlTypeName);
44         Control.Type secondControlType = new TestControlType(secondControlTypeName);
45         Control.Type thirdControlType = new TestControlType(thirdControlTypeName);
46 
47         Control firstControl = new TestControl(firstControlType);
48         Control secondControl = new TestControl(secondControlType);
49         Control thirdControl = new TestControl(thirdControlType);
50 
51         String testCompoundControlTypeName = "CompoundControl_Type_Name";
52         CompoundControl.Type testCompoundControlType
53             = new TestCompoundControlType(testCompoundControlTypeName);
54 
55         Control[] setControls = { firstControl, secondControl, thirdControl };
56         CompoundControl testedCompoundControl
57             = new TestCompoundControl(testCompoundControlType, setControls);
58 
59         // this may throw exception if bug applies
60         Control[] producedControls = testedCompoundControl.getMemberControls();
61         System.out.println("Got "+producedControls.length+" member controls.");
62 
63         // this may throw exception if bug applies
64         String producedString = testedCompoundControl.toString();
65         System.out.println("toString() returned: "+producedString);
66 
67         System.out.println("Test passed.");
68     }
69 
70 }
71 
72 class TestControl extends Control {
73 
TestControl(Control.Type type)74     TestControl(Control.Type type) {
75         super(type);
76     }
77 }
78 
79 class TestControlType extends Control.Type {
80 
TestControlType(String name)81     TestControlType(String name) {
82         super(name);
83     }
84 }
85 
86 class TestCompoundControl extends CompoundControl {
87 
TestCompoundControl(CompoundControl.Type type, Control[] memberControls)88     TestCompoundControl(CompoundControl.Type type, Control[] memberControls) {
89         super(type, memberControls);
90     }
91 }
92 
93 class TestCompoundControlType extends CompoundControl.Type {
94 
TestCompoundControlType(String name)95     TestCompoundControlType(String name) {
96         super(name);
97     }
98 }
99