Wed, 02 Mar 2011 14:03:38 -0800
6986895: compiler gives misleading message for no input files
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed Mar 02 10:56:39 2011 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed Mar 02 14:03:38 2011 -0800 1.3 @@ -1118,6 +1118,11 @@ 1.4 boolean explicitAnnotationProcessingRequested() { 1.5 return 1.6 explicitAnnotationProcessingRequested || 1.7 + explicitAnnotationProcessingRequested(options); 1.8 + } 1.9 + 1.10 + static boolean explicitAnnotationProcessingRequested(Options options) { 1.11 + return 1.12 options.isSet(PROCESSOR) || 1.13 options.isSet(PROCESSORPATH) || 1.14 options.isSet(PROC, "only") ||
2.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Wed Mar 02 10:56:39 2011 +0000 2.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Wed Mar 02 14:03:38 2011 -0800 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -367,7 +367,11 @@ 2.11 || options.isSet(VERSION) 2.12 || options.isSet(FULLVERSION)) 2.13 return EXIT_OK; 2.14 - error("err.no.source.files"); 2.15 + if (JavaCompiler.explicitAnnotationProcessingRequested(options)) { 2.16 + error("err.no.source.files.classes"); 2.17 + } else { 2.18 + error("err.no.source.files"); 2.19 + } 2.20 return EXIT_CMDERR; 2.21 } 2.22 } catch (java.io.FileNotFoundException e) {
3.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties Wed Mar 02 10:56:39 2011 +0000 3.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties Wed Mar 02 14:03:38 2011 -0800 3.3 @@ -1,5 +1,5 @@ 3.4 # 3.5 -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 3.6 +# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 3.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 # 3.9 # This code is free software; you can redistribute it and/or modify it 3.10 @@ -161,6 +161,8 @@ 3.11 invalid target release: {0} 3.12 javac.err.no.source.files=\ 3.13 no source files 3.14 +javac.err.no.source.files.classes=\ 3.15 + no source files or class names 3.16 javac.err.req.arg=\ 3.17 {0} requires an argument 3.18 javac.err.invalid.source=\
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/options/T6986895.java Wed Mar 02 14:03:38 2011 -0800 4.3 @@ -0,0 +1,66 @@ 4.4 +/* 4.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 6986895 4.30 + * @summary compiler gives misleading message for no input files 4.31 + */ 4.32 + 4.33 +import java.io.*; 4.34 +import java.util.*; 4.35 + 4.36 +public class T6986895 { 4.37 + public static void main(String... args) throws Exception { 4.38 + new T6986895().run(); 4.39 + } 4.40 + 4.41 + String noSourceFiles = "no source files"; 4.42 + String noSourceFilesOrClasses = "no source files or class names"; 4.43 + 4.44 + void run() throws Exception { 4.45 + Locale prev = Locale.getDefault(); 4.46 + try { 4.47 + Locale.setDefault(Locale.ENGLISH); 4.48 + test(noSourceFiles, "-Werror"); 4.49 + test(noSourceFilesOrClasses, "-Werror", "-Xprint"); 4.50 + } finally { 4.51 + Locale.setDefault(prev); 4.52 + } 4.53 + } 4.54 + 4.55 + void test(String expect, String... args) throws Exception { 4.56 + System.err.println("Test " + expect + ": " + Arrays.asList(args)); 4.57 + StringWriter sw = new StringWriter(); 4.58 + PrintWriter pw = new PrintWriter(sw); 4.59 + int rc = com.sun.tools.javac.Main.compile(args, pw); 4.60 + pw.close(); 4.61 + System.err.println("compilation failed; rc=" + rc); 4.62 + String out = sw.toString(); 4.63 + if (!out.isEmpty()) 4.64 + System.err.println(out); 4.65 + if (!out.contains(expect)) 4.66 + throw new Exception("expected text not found: " + expect); 4.67 + System.err.println(); 4.68 + } 4.69 +}