6595666: fix -Werror

Fri, 06 Feb 2009 10:23:57 -0800

author
jjg
date
Fri, 06 Feb 2009 10:23:57 -0800
changeset 215
9d541fd2916b
parent 213
49281ea88125
child 216
58fcba61a77d

6595666: fix -Werror
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/main/JavaCompiler.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/Main.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/javac.properties file | annotate | diff | comparison | revisions
test/tools/javac/6304921/T6304921.out file | annotate | diff | comparison | revisions
test/tools/javac/6758789/T6758789b.out file | annotate | diff | comparison | revisions
test/tools/javac/T6241723.out file | annotate | diff | comparison | revisions
test/tools/javac/T6595666.java file | annotate | diff | comparison | revisions
test/tools/javac/depDocComment/DeprecatedDocComment.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Jan 30 23:28:38 2009 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Feb 06 10:23:57 2009 -0800
     1.3 @@ -371,6 +371,7 @@
     1.4                          context.get(DiagnosticListener.class) != null;
     1.5          devVerbose    = options.get("dev") != null;
     1.6          processPcks   = options.get("process.packages") != null;
     1.7 +        werror        = options.get("-Werror")        != null;
     1.8  
     1.9          verboseCompilePolicy = options.get("verboseCompilePolicy") != null;
    1.10  
    1.11 @@ -434,6 +435,10 @@
    1.12       */
    1.13      protected boolean processPcks;
    1.14  
    1.15 +    /** Switch: treat warnings as errors
    1.16 +     */
    1.17 +    protected boolean werror;
    1.18 +
    1.19      /** Switch: is annotation processing requested explitly via
    1.20       * CompilationTask.setProcessors?
    1.21       */
    1.22 @@ -490,7 +495,11 @@
    1.23      public int errorCount() {
    1.24          if (delegateCompiler != null && delegateCompiler != this)
    1.25              return delegateCompiler.errorCount();
    1.26 -        else
    1.27 +        else {
    1.28 +            if (werror && log.nerrors == 0 && log.nwarnings > 0) {
    1.29 +                log.error("warnings.and.werror");
    1.30 +            }
    1.31 +        }
    1.32              return log.nerrors;
    1.33      }
    1.34  
     2.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java	Fri Jan 30 23:28:38 2009 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Fri Feb 06 10:23:57 2009 -0800
     2.3 @@ -406,8 +406,7 @@
     2.4                  }
     2.5              }
     2.6  
     2.7 -            if (comp.errorCount() != 0 ||
     2.8 -                options.get("-Werror") != null && comp.warningCount() != 0)
     2.9 +            if (comp.errorCount() != 0)
    2.10                  return EXIT_ERROR;
    2.11          } catch (IOException ex) {
    2.12              ioMessage(ex);
     3.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Fri Jan 30 23:28:38 2009 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Fri Feb 06 10:23:57 2009 -0800
     3.3 @@ -449,7 +449,7 @@
     3.4          },
     3.5  
     3.6          // treat warnings as errors
     3.7 -        new HiddenOption(WERROR),
     3.8 +        new Option(WERROR,                                      "opt.Werror"),
     3.9  
    3.10          // use complex inference from context in the position of a method call argument
    3.11          new HiddenOption(COMPLEXINFERENCE),
     4.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Jan 30 23:28:38 2009 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Feb 06 10:23:57 2009 -0800
     4.3 @@ -346,6 +346,9 @@
     4.4  compiler.err.pkg.clashes.with.class.of.same.name=\
     4.5      package {0} clashes with class of same name
     4.6  
     4.7 +compiler.err.warnings.and.werror=\
     4.8 +    warnings found and -Werror specified
     4.9 +
    4.10  # Errors related to annotation processing
    4.11  
    4.12  compiler.err.proc.cant.access=\
     5.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties	Fri Jan 30 23:28:38 2009 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties	Fri Feb 06 10:23:57 2009 -0800
     5.3 @@ -69,6 +69,8 @@
     5.4      Generate class files for specific VM version
     5.5  javac.opt.source=\
     5.6      Provide source compatibility with specified release
     5.7 +javac.opt.Werror=\
     5.8 +    Terminate compilation if warnings occur
     5.9  javac.opt.A=\
    5.10      Options to pass to annotation processors
    5.11  javac.opt.implicit=\
     6.1 --- a/test/tools/javac/6304921/T6304921.out	Fri Jan 30 23:28:38 2009 -0800
     6.2 +++ b/test/tools/javac/6304921/T6304921.out	Fri Feb 06 10:23:57 2009 -0800
     6.3 @@ -7,12 +7,7 @@
     6.4  required: java.util.List<java.lang.Integer>
     6.5          List<Integer> list = new ArrayList();
     6.6                               ^
     6.7 -T6304921.java:445/445/453: warning: [fallthrough] possible fall-through into case
     6.8 -        default:
     6.9 -        ^
    6.10 -T6304921.java:522/613/614: warning: [finally] finally clause cannot complete normally
    6.11 -        }
    6.12 -        ^
    6.13 +error: warnings found and -Werror specified
    6.14  T6304921.java:727/733/737: cannot find symbol
    6.15  symbol  : variable orr
    6.16  location: class java.lang.System
    6.17 @@ -21,5 +16,5 @@
    6.18  T6304921.java:812/816/822: operator + cannot be applied to int,boolean
    6.19          return 123 + true; // bad binary expression
    6.20                     ^
    6.21 -2 errors
    6.22 -4 warnings
    6.23 +3 errors
    6.24 +2 warnings
     7.1 --- a/test/tools/javac/6758789/T6758789b.out	Fri Jan 30 23:28:38 2009 -0800
     7.2 +++ b/test/tools/javac/6758789/T6758789b.out	Fri Feb 06 10:23:57 2009 -0800
     7.3 @@ -1,3 +1,5 @@
     7.4  T6758789b.java:39:11: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<X>
     7.5  T6758789b.java:39:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo<X>, T6758789a.Foo, kindname.class, T6758789a
     7.6 +- compiler.err.warnings.and.werror
     7.7 +1 error
     7.8  2 warnings
     8.1 --- a/test/tools/javac/T6241723.out	Fri Jan 30 23:28:38 2009 -0800
     8.2 +++ b/test/tools/javac/T6241723.out	Fri Feb 06 10:23:57 2009 -0800
     8.3 @@ -2,4 +2,6 @@
     8.4  T6241723.java:23:7: compiler.warn.has.been.deprecated: A2.A21, A2
     8.5  T6241723.java:26:5: compiler.warn.has.been.deprecated: Z1, unnamed package
     8.6  T6241723.java:28:7: compiler.warn.has.been.deprecated: Z2.Z21, Z2
     8.7 +- compiler.err.warnings.and.werror
     8.8 +1 error
     8.9  4 warnings
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javac/T6595666.java	Fri Feb 06 10:23:57 2009 -0800
     9.3 @@ -0,0 +1,68 @@
     9.4 +/*
     9.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    9.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    9.24 + * have any questions.
    9.25 + */
    9.26 +
    9.27 +/*
    9.28 + * @test
    9.29 + * @bug 6595666
    9.30 + * @summary fix -Werror
    9.31 + */
    9.32 +
    9.33 +import java.io.*;
    9.34 +import java.util.*;
    9.35 +
    9.36 +public class T6595666 {
    9.37 +    void m() {
    9.38 +        // the following line must create warnings with -Xlint, because of unchecked conversion
    9.39 +        List<Integer> list = new ArrayList();
    9.40 +    }
    9.41 +
    9.42 +    public static void main(String... args) throws Exception {
    9.43 +        File testSrc = new File(System.getProperty("test.src", "."));
    9.44 +
    9.45 +        String basename = T6595666.class.getName();
    9.46 +        File srcFile = new File(testSrc, basename+".java");
    9.47 +        File classFile = new File(basename+".class");
    9.48 +        classFile.delete();
    9.49 +        if (classFile.exists())
    9.50 +            throw new Exception("setup error, can't delete " + classFile);
    9.51 +
    9.52 +        compile(1, "-d", ".", "-Xlint", "-Werror", srcFile.getPath());
    9.53 +        if (classFile.exists())
    9.54 +            throw new Exception("failed: found " + classFile);
    9.55 +
    9.56 +        compile(0, "-d", ".", "-Xlint", srcFile.getPath());
    9.57 +        if (!classFile.exists())
    9.58 +            throw new Exception("failed: " + classFile + " not found");
    9.59 +    }
    9.60 +
    9.61 +    private static void compile(int rc, String... args) throws Exception {
    9.62 +        System.err.println("compile: " + Arrays.asList(args));
    9.63 +        StringWriter sw = new StringWriter();
    9.64 +        PrintWriter pw = new PrintWriter(sw);
    9.65 +        int rc2 = com.sun.tools.javac.Main.compile(args, pw);
    9.66 +        pw.close();
    9.67 +        System.err.println(sw);
    9.68 +        if (rc != rc2)
    9.69 +            throw new Exception("bad exit code; expected " + rc + ", found " + rc2);
    9.70 +    }
    9.71 +}
    10.1 --- a/test/tools/javac/depDocComment/DeprecatedDocComment.out	Fri Jan 30 23:28:38 2009 -0800
    10.2 +++ b/test/tools/javac/depDocComment/DeprecatedDocComment.out	Fri Feb 06 10:23:57 2009 -0800
    10.3 @@ -1,4 +1,6 @@
    10.4  DeprecatedDocComment.java:27:28: compiler.warn.has.been.deprecated: deprecatedTest1(), DeprecatedDocComment2
    10.5  DeprecatedDocComment.java:31:28: compiler.warn.has.been.deprecated: deprecatedTest5(), DeprecatedDocComment2
    10.6  DeprecatedDocComment.java:32:28: compiler.warn.has.been.deprecated: deprecatedTest6(), DeprecatedDocComment2
    10.7 +- compiler.err.warnings.and.werror
    10.8 +1 error
    10.9  3 warnings

mercurial