/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5035217 6766173
* @summary Test that MBean's RuntimeException is wrapped in
* RuntimeMBeanException and (for Standard MBeans) that checked exceptions
* are wrapped in MBeanException
* @author Eamonn McManus
* @compile MBeanExceptionTest.java
* @run main MBeanExceptionTest
*/
public class MBeanExceptionTest {
"it is wrapped in RuntimeMBeanException,");
"it is wrapped in MBeanException");
new ObjectName(":name=Instance of StandardMBean");
int failures = 0;
final boolean[] booleans = {false, true};
"in " + excS);
// E.g. "Test that, with a plain MBeanServer, an MBeanException
// is wrapped in an MBeanException".
try {
"FAIL: createMBean succeeded but should not have");
failures++;
} catch (Exception e) {
if (!excC.isInstance(e)) {
"createMBean, got " + e);
failures++;
} else {
", got " + e);
failures++;
} else
}
}
}
if (failures == 0)
else {
}
}
boolean testChecked)
throws Exception {
int failures = 0;
if (j == CHECKED && !testChecked)
continue;
try {
switch (i) {
case GET:
break;
case SET:
break;
case INVOKE:
break;
default:
throw new AssertionError();
}
failures++;
} catch (RuntimeMBeanException e) {
if (j == CHECKED) {
"when checked expected: " + e);
failures++;
} else {
if (cause == theUncheckedException)
else {
" wrapped " + cause);
failures++;
}
}
} catch (MBeanException e) {
if (j == UNCHECKED) {
"when unchecked expected: " + e);
failures++;
} else {
if (cause == theCheckedException)
else {
" wrapped " + cause);
failures++;
}
}
} catch (Throwable t) {
failures++;
}
}
}
return failures;
}
public static interface ExceptMBean {
public void UncheckedException();
}
public Except() {}
if (runtimeX)
else
}
throw theUncheckedException;
}
throw theUncheckedException;
}
public void UncheckedException() {
throw theUncheckedException;
}
throw theCheckedException;
}
throw theCheckedException;
}
throw theCheckedException;
}
}
throws MBeanException {
throw theUncheckedException;
else
throw new AssertionError();
}
throws MBeanException {
throw theUncheckedException;
else
throw new AssertionError();
}
throws MBeanException {
throw theUncheckedException;
else
throw new AssertionError();
}
assert false;
return null;
}
assert false;
return null;
}
try {
.getMBeanInfo();
} catch (Exception e) {
assert false;
return null;
}
}
}
new Exception("The checked exception that should be seen");
new UnsupportedOperationException("The unchecked exception " +
"that should be seen");
}