test/jdk/java/net/URL/HandlerLoop.java
changeset 52763 c392f7b60fd9
parent 47216 71c04702a3d5
child 54201 83cace4142c8
equal deleted inserted replaced
52762:b3866f3879e1 52763:c392f7b60fd9
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.*;
    24 import java.lang.reflect.InvocationTargetException;
       
    25 import java.net.URL;
       
    26 import java.net.URLStreamHandler;
       
    27 import java.net.URLStreamHandlerFactory;
       
    28 
    25 /*
    29 /*
    26  * @test
    30  * @test
    27  * @bug 4135031
    31  * @bug 4135031
    28  * @summary Test boostrap problem when a URLStreamHandlerFactory is loaded
    32  * @summary Test bootstrap problem when a URLStreamHandlerFactory is loaded
    29  *          by the application class loader.
    33  *          by the application class loader.
    30  *
    34  * @modules java.base/sun.net.www.protocol.file
       
    35  * @run main HandlerLoop
    31  */
    36  */
    32 import java.net.*;
       
    33 
       
    34 public class HandlerLoop {
    37 public class HandlerLoop {
    35 
    38 
    36     public static void main(String args[]) throws Exception {
    39     public static void main(String args[]) throws Exception {
    37         URL.setURLStreamHandlerFactory(
    40         URL.setURLStreamHandlerFactory(
    38             new HandlerFactory("sun.net.www.protocol"));
    41             new HandlerFactory("sun.net.www.protocol"));
    55             // problem as the stream handler factory will be reentered
    58             // problem as the stream handler factory will be reentered
    56             // over and over again if the application class loader
    59             // over and over again if the application class loader
    57             // shares the same stream handler factory.
    60             // shares the same stream handler factory.
    58             new Dummy();
    61             new Dummy();
    59             try {
    62             try {
    60                 Class c = Class.forName(name);
    63                 Class<?> c = Class.forName(name);
    61                 return (URLStreamHandler)c.newInstance();
    64                 return (URLStreamHandler)c.getDeclaredConstructor().newInstance();
    62             } catch (ClassNotFoundException e) {
    65             } catch (ClassNotFoundException |
    63                 e.printStackTrace();
    66                     IllegalAccessException |
    64             } catch (IllegalAccessException e) {
    67                     InstantiationException |
    65                 e.printStackTrace();
    68                     NoSuchMethodException |
    66             } catch (InstantiationException e) {
    69                     InvocationTargetException e) {
    67                 e.printStackTrace();
    70                 e.printStackTrace();
    68             }
    71             }
    69             return null;
    72             return null;
    70         }
    73         }
    71     }
    74     }