1/* 2 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 6400207 27 * @summary JSR 199: JavaFileManager.list and unset location 28 * @author Peter von der Ah\u00e9 29 * @modules java.compiler 30 * jdk.compiler 31 */ 32 33import java.util.*; 34import javax.tools.*; 35import static javax.tools.StandardLocation.*; 36import static javax.tools.JavaFileObject.Kind.*; 37 38public class T6400207 { 39 static void testList(JavaFileManager fm, 40 JavaFileManager.Location location, 41 String packageName, 42 Set<JavaFileObject.Kind> kinds) throws Exception { 43 boolean expectNpe = 44 location == null || 45 packageName == null || 46 kinds == null; 47 try { 48 fm.list(location, packageName, kinds, false); 49 if (expectNpe) { 50 String message = "NullPointerException not thrown"; 51 if (location == null) 52 throw new AssertionError(message + " (location is null)"); 53 if (packageName == null) 54 throw new AssertionError(message + " (packageName is null)"); 55 if (kinds == null) 56 throw new AssertionError(message + " (kinds is null)"); 57 throw new AssertionError(message); 58 } 59 } catch (NullPointerException e) { 60 if (!expectNpe) 61 throw e; 62 } 63 } 64 65 public static void main(String... args) throws Exception { 66 try (JavaFileManager fm = 67 ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) { 68 JavaFileManager.Location bogusLocation = locationFor("bogus"); 69 JavaFileManager.Location knownLocation = CLASS_PATH; 70 String packageName = "java.lang"; 71 Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS); 72 73 for (StandardLocation location : StandardLocation.values()) { 74 if (location != locationFor(location.getName())) 75 throw new AssertionError(location + " != locationFor(" + 76 location.getName() + ")"); 77 } 78 79 testList(fm, null, null, null); 80 testList(fm, bogusLocation, packageName, kinds); 81 testList(fm, knownLocation, packageName, kinds); 82 testList(fm, null, packageName, kinds); 83 testList(fm, knownLocation, null, kinds); 84 testList(fm, knownLocation, packageName, null); 85 testList(fm, bogusLocation, null, kinds); 86 testList(fm, bogusLocation, packageName, null); 87 88 System.err.println("Test PASSED."); 89 } 90 } 91} 92