7022337: repeated warnings about bootclasspath not set

Mon, 28 Feb 2011 12:19:18 -0800

author
jjg
date
Mon, 28 Feb 2011 12:19:18 -0800
changeset 897
9029f694e5df
parent 896
9f9df9684cfc
child 898
bf9f162c7104

7022337: repeated warnings about bootclasspath not set
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/main/JavaCompiler.java file | annotate | diff | comparison | revisions
test/tools/javac/T6900037.java file | annotate | diff | comparison | revisions
test/tools/javac/T6900037.out file | annotate | diff | comparison | revisions
test/tools/javac/options/T6900037.java file | annotate | diff | comparison | revisions
test/tools/javac/options/T6900037.out file | annotate | diff | comparison | revisions
test/tools/javac/options/T7022337.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Mon Feb 28 11:50:56 2011 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Mon Feb 28 12:19:18 2011 -0800
     1.3 @@ -299,6 +299,13 @@
     1.4      protected JavaCompiler delegateCompiler;
     1.5  
     1.6      /**
     1.7 +     * Command line options.
     1.8 +     */
     1.9 +    protected Options options;
    1.10 +
    1.11 +    protected Context context;
    1.12 +
    1.13 +    /**
    1.14       * Flag set if any annotation processing occurred.
    1.15       **/
    1.16      protected boolean annotationProcessingOccurred;
    1.17 @@ -308,8 +315,6 @@
    1.18       **/
    1.19      protected boolean implicitSourceFilesRead;
    1.20  
    1.21 -    protected Context context;
    1.22 -
    1.23      /** Construct a new compiler using a shared context.
    1.24       */
    1.25      public JavaCompiler(Context context) {
    1.26 @@ -354,7 +359,7 @@
    1.27  
    1.28          reader.sourceCompleter = this;
    1.29  
    1.30 -        Options options = Options.instance(context);
    1.31 +        options = Options.instance(context);
    1.32  
    1.33          verbose       = options.isSet(VERBOSE);
    1.34          sourceOutput  = options.isSet(PRINTSOURCE); // used to be -s
    1.35 @@ -792,6 +797,11 @@
    1.36              throw new AssertionError("attempt to reuse JavaCompiler");
    1.37          hasBeenUsed = true;
    1.38  
    1.39 +        // forcibly set the equivalent of -Xlint:-options, so that no further
    1.40 +        // warnings about command line options are generated from this point on
    1.41 +        options.put(XLINT_CUSTOM + "-" + LintCategory.OPTIONS.option, "true");
    1.42 +        options.remove(XLINT_CUSTOM + LintCategory.OPTIONS.option);
    1.43 +
    1.44          start_msec = now();
    1.45  
    1.46          try {
    1.47 @@ -963,7 +973,6 @@
    1.48      public void initProcessAnnotations(Iterable<? extends Processor> processors) {
    1.49          // Process annotations if processing is not disabled and there
    1.50          // is at least one Processor available.
    1.51 -        Options options = Options.instance(context);
    1.52          if (options.isSet(PROC, "none")) {
    1.53              processAnnotations = false;
    1.54          } else if (procEnvImpl == null) {
    1.55 @@ -1022,7 +1031,6 @@
    1.56              // If there are no annotation processors present, and
    1.57              // annotation processing is to occur with compilation,
    1.58              // emit a warning.
    1.59 -            Options options = Options.instance(context);
    1.60              if (options.isSet(PROC, "only")) {
    1.61                  log.warning("proc.proc-only.requested.no.procs");
    1.62                  todo.clear();
    1.63 @@ -1108,7 +1116,6 @@
    1.64      }
    1.65  
    1.66      boolean explicitAnnotationProcessingRequested() {
    1.67 -        Options options = Options.instance(context);
    1.68          return
    1.69              explicitAnnotationProcessingRequested ||
    1.70              options.isSet(PROCESSOR) ||
     2.1 --- a/test/tools/javac/T6900037.java	Mon Feb 28 11:50:56 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,34 +0,0 @@
     2.4 -/*
     2.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 - *
     2.8 - * This code is free software; you can redistribute it and/or modify it
     2.9 - * under the terms of the GNU General Public License version 2 only, as
    2.10 - * published by the Free Software Foundation.
    2.11 - *
    2.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 - * version 2 for more details (a copy is included in the LICENSE file that
    2.16 - * accompanied this code).
    2.17 - *
    2.18 - * You should have received a copy of the GNU General Public License version
    2.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 - *
    2.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 - * or visit www.oracle.com if you need additional information or have any
    2.24 - * questions.
    2.25 - */
    2.26 -
    2.27 -/*
    2.28 - * @test
    2.29 - * @bug 6900037
    2.30 - * @summary javac should warn if earlier -source is used and bootclasspath not set
    2.31 - * @compile T6900037.java
    2.32 - * @compile -source 1.6 T6900037.java
    2.33 - * @compile/fail/ref=T6900037.out -XDrawDiagnostics -Werror -source 1.6 T6900037.java
    2.34 - * @compile -Werror -source 1.6 -Xlint:-options T6900037.java
    2.35 - */
    2.36 -
    2.37 -class T6900037 { }
     3.1 --- a/test/tools/javac/T6900037.out	Mon Feb 28 11:50:56 2011 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,4 +0,0 @@
     3.4 -- compiler.warn.source.no.bootclasspath: 1.6
     3.5 -- compiler.err.warnings.and.werror
     3.6 -1 error
     3.7 -1 warning
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/options/T6900037.java	Mon Feb 28 12:19:18 2011 -0800
     4.3 @@ -0,0 +1,34 @@
     4.4 +/*
     4.5 + * Copyright (c) 2010, 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 6900037
    4.30 + * @summary javac should warn if earlier -source is used and bootclasspath not set
    4.31 + * @compile T6900037.java
    4.32 + * @compile -source 1.6 T6900037.java
    4.33 + * @compile/fail/ref=T6900037.out -XDrawDiagnostics -Werror -source 1.6 T6900037.java
    4.34 + * @compile -Werror -source 1.6 -Xlint:-options T6900037.java
    4.35 + */
    4.36 +
    4.37 +class T6900037 { }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/options/T6900037.out	Mon Feb 28 12:19:18 2011 -0800
     5.3 @@ -0,0 +1,4 @@
     5.4 +- compiler.warn.source.no.bootclasspath: 1.6
     5.5 +- compiler.err.warnings.and.werror
     5.6 +1 error
     5.7 +1 warning
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/options/T7022337.java	Mon Feb 28 12:19:18 2011 -0800
     6.3 @@ -0,0 +1,107 @@
     6.4 +/*
     6.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +
    6.28 +/*
    6.29 + * @test
    6.30 + * @bug 7022337
    6.31 + * @summary repeated warnings about bootclasspath not set
    6.32 + * @library ../lib
    6.33 + * @build JavacTestingAbstractProcessor T7022337
    6.34 + * @run main T7022337
    6.35 + */
    6.36 +
    6.37 +import java.io.*;
    6.38 +import java.util.*;
    6.39 +import javax.annotation.processing.*;
    6.40 +import javax.lang.model.element.*;
    6.41 +import javax.tools.*;
    6.42 +
    6.43 +public class T7022337 extends JavacTestingAbstractProcessor {
    6.44 +    public static void main(String... args) throws Exception {
    6.45 +        new T7022337().run();
    6.46 +    }
    6.47 +
    6.48 +    void run() throws Exception {
    6.49 +        String myName = T7022337.class.getSimpleName();
    6.50 +        File testSrc = new File(System.getProperty("test.src"));
    6.51 +        File file = new File(testSrc, myName + ".java");
    6.52 +
    6.53 +        String out = compile(
    6.54 +            "-XDrawDiagnostics",
    6.55 +            "-d", ".",
    6.56 +            "-processor", myName,
    6.57 +            "-source", "6", // explicit use of older source value without bootclasspath
    6.58 +            file.getPath());
    6.59 +
    6.60 +        int count = 0;
    6.61 +        for (String line: out.split("[\r\n]+")) {
    6.62 +            if (line.contains("compiler.warn.source.no.bootclasspath"))
    6.63 +                count++;
    6.64 +        }
    6.65 +        if (count != 1)
    6.66 +            throw new Exception("unexpected number of warnings found: " + count + ", expected: 1");
    6.67 +    }
    6.68 +
    6.69 +    String compile(String... args) throws Exception {
    6.70 +        StringWriter sw = new StringWriter();
    6.71 +        PrintWriter pw = new PrintWriter(sw);
    6.72 +        int rc = com.sun.tools.javac.Main.compile(args, pw);
    6.73 +        pw.close();
    6.74 +        String out = sw.toString();
    6.75 +        if (!out.isEmpty())
    6.76 +            System.err.println(out);
    6.77 +        if (rc != 0)
    6.78 +            throw new Exception("compilation failed unexpectedly: rc=" + rc);
    6.79 +        return out;
    6.80 +    }
    6.81 +
    6.82 +    // ----------
    6.83 +
    6.84 +    int round = 0;
    6.85 +
    6.86 +    @Override
    6.87 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    6.88 +        round++;
    6.89 +
    6.90 +        final int MAXROUNDS = 3;
    6.91 +        if (round < MAXROUNDS)
    6.92 +            generate("Gen" + round);
    6.93 +
    6.94 +        return true;
    6.95 +    }
    6.96 +
    6.97 +    void generate(String name) {
    6.98 +        try {
    6.99 +            JavaFileObject fo = filer.createSourceFile(name);
   6.100 +            Writer out = fo.openWriter();
   6.101 +            try {
   6.102 +                out.write("class " + name + " { }");
   6.103 +            } finally {
   6.104 +                out.close();
   6.105 +            }
   6.106 +        } catch (IOException e) {
   6.107 +            throw new Error(e);
   6.108 +        }
   6.109 +    }
   6.110 +}

mercurial