test/jdk/javax/management/MBeanInfo/NotificationInfoTest.java
author lfoltan
Tue, 20 Feb 2018 07:46:40 -0500
changeset 49026 844bf1deff1a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196884: VS2017 Multiple Type Cast Conversion Compilation Errors Summary: Change the type of symbolic constant badAddressVal and introduce specific casts to fix multiple type cast conversion compilation errors. Reviewed-by: coleenp, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 27034
diff changeset
     2
 * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 5012634
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that JMX classes use fully-qualified class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * in MBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Eamonn McManus
43503
bc7f8619ab70 8173607: JMX RMI connector should be in its own module
dfuchs
parents: 36511
diff changeset
    30
 * @modules java.management.rmi
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean NotificationInfoTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build NotificationInfoTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main NotificationInfoTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.*;
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
    37
import java.lang.management.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.*;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    40
import java.nio.file.FileSystem;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    41
import java.nio.file.FileSystems;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    42
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    43
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    44
import java.nio.file.Paths;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.*;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    46
import java.util.stream.Collectors;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.relation.*;
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
    49
import javax.management.remote.*;
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
    50
import javax.management.remote.rmi.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This test finds all classes in the same code-base as the JMX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * classes that look like Standard MBeans, and checks that if they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * NotificationBroadcasters they declare existent notification types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * A class looks like a Standard MBean if both Thing and ThingMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * classes exist.  So for example javax.management.timer.Timer looks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * like a Standard MBean because javax.management.timer.TimerMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * exists.  Timer is instanceof NotificationBroadcaster, so we expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * that ((NotificationBroadcaster) timer).getNotificationInfo() will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * return an array of MBeanNotificationInfo where each entry has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * getName() that names an existent Java class that is a Notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * An MBean is "suspicious" if it is a NotificationBroadcaster but its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * MBeanNotificationInfo[] is empty.  This is legal, but surprising.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * In order to call getNotificationInfo(), we need an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * class.  We attempt to make one by calling a public no-arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * constructor.  But the "construct" method below can be extended to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * construct specific MBean classes for which the no-arg constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * The test is obviously not exhaustive, but does catch the cases that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * failed in 5012634.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public class NotificationInfoTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // class or object names where the test failed
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
    78
    private static final Set<String> failed = new TreeSet<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // class or object names where there were no MBeanNotificationInfo entries
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
    81
    private static final Set<String> suspicious = new TreeSet<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        System.out.println("Checking that all known MBeans that are " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                           "NotificationBroadcasters have sane " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                           "MBeanInfo.getNotifications()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        System.out.println("Checking platform MBeans...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        checkPlatformMBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    91
        URL codeBase;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    92
        String home = System.getProperty("java.home");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    93
        Path classFile = Paths.get(home, "modules", "java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    94
        if (Files.isDirectory(classFile)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    95
            codeBase = classFile.toUri().toURL();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    96
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
    97
            codeBase = URI.create("jrt:/java.management").toURL();
27034
ac2dd06dba4a 8060166: javax/management/MBeanInfo/NotificationInfoTest.java fails with modular image
alanb
parents: 5506
diff changeset
    98
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        System.out.println("Looking for standard MBeans...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        String[] classes = findStandardMBeans(codeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        System.out.println("Testing standard MBeans...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            String name = classes[i];
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   107
            Class<?> c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                c = Class.forName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                System.out.println(name + ": cannot load (not public?): " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (!NotificationBroadcaster.class.isAssignableFrom(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                System.out.println(name + ": not a NotificationBroadcaster");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   118
            if (Modifier.isAbstract(c.getModifiers())) {
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   119
                System.out.println(name + ": abstract class");
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   120
                continue;
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   121
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            NotificationBroadcaster mbean;
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   124
            Constructor<?> constr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            try {
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   126
                constr = c.getConstructor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                System.out.println(name + ": no public no-arg constructor: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                   + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            try {
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   133
                mbean = (NotificationBroadcaster) constr.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                System.out.println(name + ": no-arg constructor failed: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            check(mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        System.out.println("Testing some explicit cases...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        check(new RelationService(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
          We can't do this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            check(new RequiredModelMBean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
          because the Model MBean spec more or less forces us to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
          names GENERIC and ATTRIBUTE_CHANGE for its standard notifs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        checkRMIConnectorServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (!suspicious.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            System.out.println("SUSPICIOUS CLASSES: " + suspicious);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (failed.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            System.out.println("TEST PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            System.out.println("TEST FAILED: " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static void check(NotificationBroadcaster mbean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        System.out.print(mbean.getClass().getName() + ": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        check(mbean.getClass().getName(), mbean.getNotificationInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static void checkPlatformMBeans() throws Exception {
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   174
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   175
        Set<ObjectName> mbeanNames = mbs.queryNames(null, null);
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   176
        for (ObjectName name : mbeanNames) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (!mbs.isInstanceOf(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                  NotificationBroadcaster.class.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                System.out.println(name + ": not a NotificationBroadcaster");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                MBeanInfo mbi = mbs.getMBeanInfo(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                check(name.toString(), mbi.getNotifications());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static void checkRMIConnectorServer() throws Exception {
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   188
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   189
        RMIConnectorServer connector = new RMIConnectorServer(url, null);
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   190
        check(connector);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static void check(String what, MBeanNotificationInfo[] mbnis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        System.out.print(what + ": checking notification info: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (mbnis.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            System.out.println("NONE (suspicious)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            suspicious.add(what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // Each MBeanNotificationInfo.getName() should be an existent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // Java class that is Notification or a subclass of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        for (int j = 0; j < mbnis.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            String notifClassName = mbnis[j].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                Class notifClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    notifClass = Class.forName(notifClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    System.out.print("FAILED(" + notifClassName + ": " + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                     ") ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    failed.add(what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (!Notification.class.isAssignableFrom(notifClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    System.out.print("FAILED(" + notifClassName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                     ": not a Notification) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    failed.add(what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                System.out.print("OK(" + notifClassName + ") ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   226
    private static String[] findStandardMBeans(URL codeBase) throws Exception {
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   227
        Set<String> names;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   228
        if (codeBase.getProtocol().equalsIgnoreCase("jrt")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   229
            names = findStandardMBeansFromRuntime();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   230
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            names = findStandardMBeansFromDir(codeBase);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   232
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   234
        Set<String> standardMBeanNames = new TreeSet<String>();
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   235
        for (String name : names) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (name.endsWith("MBean")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                String prefix = name.substring(0, name.length() - 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (names.contains(prefix))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    standardMBeanNames.add(prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   242
        return standardMBeanNames.toArray(new String[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   245
    private static Set<String> findStandardMBeansFromRuntime() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   246
        FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   247
        Path modules = fs.getPath("/modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   248
        return Files.walk(modules)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   249
                .filter(path -> path.toString().endsWith(".class"))
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   250
                .map(path -> path.subpath(2, path.getNameCount()))
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   251
                .map(Path::toString)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   252
                .map(s -> s.substring(0, s.length() - 6))  // drop .class
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   253
                .filter(s -> !s.equals("module-info"))
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   254
                .map(s -> s.replace('/', '.'))
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   255
                .collect(Collectors.toSet());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   258
    private static Set<String> findStandardMBeansFromDir(URL codeBase)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        File dir = new File(new URI(codeBase.toString()));
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   261
        Set<String> names = new TreeSet<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        scanDir(dir, "", names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
1155
a9a142fcf1b5 6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
emcmanus
parents: 2
diff changeset
   266
    private static void scanDir(File dir, String prefix, Set<String> names)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        File[] files = dir.listFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (files == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        for (int i = 0; i < files.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            File f = files[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            String name = f.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            String p = (prefix.equals("")) ? name : prefix + "." + name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (f.isDirectory())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                scanDir(f, p, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            else if (name.endsWith(".class")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                p = p.substring(0, p.length() - 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                names.add(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}