mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-25 07:09:55 +00:00
6750935: The expected NotCompliantMBeanException is not thrown for the custom MXBeanMappingFactory
6751872: MXBeanMappingFactory example says "implements" when it should be "extends" Reviewed-by: dfuchs
This commit is contained in:
parent
71365ab05c
commit
6caae4568d
@ -228,7 +228,15 @@ public class Introspector {
|
||||
// to generate the appropriate exception.
|
||||
}
|
||||
if (c != null) {
|
||||
MXBeanMappingFactory factory = MXBeanMappingFactory.forInterface(c);
|
||||
MXBeanMappingFactory factory;
|
||||
try {
|
||||
factory = MXBeanMappingFactory.forInterface(c);
|
||||
} catch (IllegalArgumentException e) {
|
||||
NotCompliantMBeanException ncmbe =
|
||||
new NotCompliantMBeanException(e.getMessage());
|
||||
ncmbe.initCause(e);
|
||||
throw ncmbe;
|
||||
}
|
||||
return new MXBeanSupport(mbean, c, factory);
|
||||
}
|
||||
checkCompliance(mbeanClass);
|
||||
|
||||
@ -36,7 +36,6 @@ import javax.management.MBeanServer;
|
||||
import javax.management.NotCompliantMBeanException;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.openmbean.MXBeanMappingFactory;
|
||||
import javax.management.openmbean.MXBeanMappingFactoryClass;
|
||||
|
||||
/**
|
||||
* Base class for MXBeans.
|
||||
|
||||
@ -48,7 +48,7 @@ import java.lang.reflect.Type;
|
||||
* effect by defining {@code MyLinkedListMappingFactory} as follows:</p>
|
||||
*
|
||||
* <pre>
|
||||
* public class MyLinkedListMappingFactory implements MXBeanMappingFactory {
|
||||
* public class MyLinkedListMappingFactory extends MXBeanMappingFactory {
|
||||
* public MyLinkedListMappingFactory() {}
|
||||
*
|
||||
* public MXBeanMapping mappingForType(Type t, MXBeanMappingFactory f)
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/* @test %M% %I%
|
||||
* @bug 6562936
|
||||
* @bug 6562936 6750935
|
||||
* @run compile customtypes/package-info.java
|
||||
* @run main CustomTypeTest
|
||||
*/
|
||||
@ -342,6 +342,38 @@ public class CustomTypeTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BadConstructorMXBeanMappingFactory1 extends
|
||||
MXBeanMappingFactory {
|
||||
private BadConstructorMXBeanMappingFactory1() {}
|
||||
|
||||
@Override
|
||||
public MXBeanMapping mappingForType(Type arg0, MXBeanMappingFactory arg1)
|
||||
throws OpenDataException {
|
||||
throw new UnsupportedOperationException("Should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
public static class BadConstructorMXBeanMappingFactory2 extends
|
||||
MXBeanMappingFactory {
|
||||
public BadConstructorMXBeanMappingFactory2(boolean oops) {}
|
||||
|
||||
@Override
|
||||
public MXBeanMapping mappingForType(Type arg0, MXBeanMappingFactory arg1)
|
||||
throws OpenDataException {
|
||||
throw new UnsupportedOperationException("Should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
@MXBeanMappingFactoryClass(BadConstructorMXBeanMappingFactory1.class)
|
||||
public static interface BadConstructor1MXBean {}
|
||||
|
||||
public static class BadConstructor1 implements BadConstructor1MXBean {}
|
||||
|
||||
@MXBeanMappingFactoryClass(BadConstructorMXBeanMappingFactory2.class)
|
||||
public static interface BadConstructor2MXBean {}
|
||||
|
||||
public static class BadConstructor2 implements BadConstructor2MXBean {}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||
|
||||
@ -407,8 +439,10 @@ public class CustomTypeTest {
|
||||
try {
|
||||
mbs.registerMBean(new ReallyBrokenImpl(), new ObjectName("d:type=Broken"));
|
||||
fail("Register did not throw exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (NotCompliantMBeanException e) {
|
||||
System.out.println("...OK: threw: " + e);
|
||||
} catch (Exception e) {
|
||||
fail("Register threw wrong exception: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Test MXBeanMappingFactory exception with StandardMBean");
|
||||
@ -433,6 +467,24 @@ public class CustomTypeTest {
|
||||
System.out.println("...OK: threw: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Test MXBeanMappingFactoryClass constructor exception");
|
||||
for (Object mbean : new Object[] {
|
||||
new BadConstructor1(), new BadConstructor2(),
|
||||
}) {
|
||||
String testName = mbean.getClass().getSimpleName();
|
||||
try {
|
||||
ObjectName name = new ObjectName("d:type=" + testName);
|
||||
mbs.registerMBean(mbean, name);
|
||||
fail("Broken MXBeanMappingFactoryClass did not throw exception" +
|
||||
" (" + testName + ")");
|
||||
} catch (NotCompliantMBeanException e) {
|
||||
System.out.println("...OK: " + testName + " threw: " + e);
|
||||
} catch (Exception e) {
|
||||
fail("Broken MXBeanMappingFactoryClass " + testName + " threw " +
|
||||
"wrong exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
if (failure == null)
|
||||
System.out.println("TEST PASSED");
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user