langtools/test/tools/javac/T6351767.java
changeset 27319 030080f03e4f
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    36 
    36 
    37 public class T6351767 {
    37 public class T6351767 {
    38     public static void main(String... args) throws Exception {
    38     public static void main(String... args) throws Exception {
    39 
    39 
    40         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    40         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    41         JavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
    41         try (JavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
    42 
    42 
    43         // test null
    43             // test null
    44         try {
    44             try {
    45             jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
    45                 jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
    46             error("NPE not thrown");
    46                 error("NPE not thrown");
       
    47             }
       
    48             catch (NullPointerException e) {
       
    49                 // expected
       
    50             }
       
    51 
       
    52             // test null fileKinds
       
    53             try {
       
    54                 jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
       
    55                 error("NPE not thrown");
       
    56             }
       
    57             catch (NullPointerException e) {
       
    58                 // expected
       
    59             }
       
    60 
       
    61             // test good package
       
    62             boolean found = false;
       
    63             for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
       
    64                                                "java.lang",
       
    65                                                EnumSet.of(Kind.CLASS),
       
    66                                                false)) {
       
    67                 System.err.println("found " + jfo.toUri());
       
    68                 if (jfo.isNameCompatible("Object", Kind.CLASS))
       
    69                     found = true;
       
    70             }
       
    71             if (!found)
       
    72                 error("expected file, java/lang/Object.class, not found");
       
    73 
       
    74             found = false;
       
    75             // test good package (VM name)
       
    76             for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
       
    77                                                "java/lang",
       
    78                                                EnumSet.of(Kind.CLASS),
       
    79                                                false)) {
       
    80                 System.err.println("found " + jfo.toUri());
       
    81                 if (jfo.isNameCompatible("Object", Kind.CLASS))
       
    82                     found = true;
       
    83             }
       
    84             if (!found)
       
    85                 error("expected file, java/lang/Object.class, not found");
    47         }
    86         }
    48         catch (NullPointerException e) {
       
    49             // expected
       
    50         }
       
    51 
       
    52         // test null fileKinds
       
    53         try {
       
    54             jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
       
    55             error("NPE not thrown");
       
    56         }
       
    57         catch (NullPointerException e) {
       
    58             // expected
       
    59         }
       
    60 
       
    61         // test good package
       
    62         boolean found = false;
       
    63         for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
       
    64                                            "java.lang",
       
    65                                            EnumSet.of(Kind.CLASS),
       
    66                                            false)) {
       
    67             System.err.println("found " + jfo.toUri());
       
    68             if (jfo.isNameCompatible("Object", Kind.CLASS))
       
    69                 found = true;
       
    70         }
       
    71         if (!found)
       
    72             error("expected file, java/lang/Object.class, not found");
       
    73 
       
    74         found = false;
       
    75         // test good package (VM name)
       
    76         for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
       
    77                                            "java/lang",
       
    78                                            EnumSet.of(Kind.CLASS),
       
    79                                            false)) {
       
    80             System.err.println("found " + jfo.toUri());
       
    81             if (jfo.isNameCompatible("Object", Kind.CLASS))
       
    82                 found = true;
       
    83         }
       
    84         if (!found)
       
    85             error("expected file, java/lang/Object.class, not found");
       
    86 
       
    87     }
    87     }
    88 
    88 
    89     static void error(String msg) {
    89     static void error(String msg) {
    90         throw new AssertionError(msg);
    90         throw new AssertionError(msg);
    91     }
    91     }