Merge

Fri, 06 Feb 2009 17:24:04 -0800

author
tbell
date
Fri, 06 Feb 2009 17:24:04 -0800
changeset 217
000d1e518bc5
parent 214
638d5fbf5e78
parent 216
58fcba61a77d
child 218
c53007f34195
child 221
6ada6122dd4f

Merge

     1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Feb 06 09:44:58 2009 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Feb 06 17:24:04 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 Feb 06 09:44:58 2009 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Fri Feb 06 17:24:04 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 Feb 06 09:44:58 2009 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Fri Feb 06 17:24:04 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 Feb 06 09:44:58 2009 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Feb 06 17:24:04 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 Feb 06 09:44:58 2009 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties	Fri Feb 06 17:24:04 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 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/share/classes/javax/lang/model/UnknownEntityException.java	Fri Feb 06 17:24:04 2009 -0800
     6.3 @@ -0,0 +1,57 @@
     6.4 +/*
     6.5 + * Copyright 2009 Sun Microsystems, Inc.  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.  Sun designates this
    6.11 + * particular file as subject to the "Classpath" exception as provided
    6.12 + * by Sun in the LICENSE file that accompanied this code.
    6.13 + *
    6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 + * version 2 for more details (a copy is included in the LICENSE file that
    6.18 + * accompanied this code).
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License version
    6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 + *
    6.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.26 + * have any questions.
    6.27 + */
    6.28 +
    6.29 +package javax.lang.model;
    6.30 +
    6.31 +/**
    6.32 + * Superclass of exceptions which indicate that an unknown kind of
    6.33 + * entity was encountered.  This situation can occur if the language
    6.34 + * evolves and new kinds of constructs are introduced.  Subclasses of
    6.35 + * this exception may be thrown by visitors to indicate that the
    6.36 + * visitor was created for a prior version of the language.
    6.37 + *
    6.38 + * <p>A common superclass for those exceptions allows a single catch
    6.39 + * block to have code handling them uniformly.
    6.40 + *
    6.41 + * @author Joseph D. Darcy
    6.42 + * @see javax.lang.model.element.UnknownElementException
    6.43 + * @see javax.lang.model.element.UnknownAnnotationValueException
    6.44 + * @see javax.lang.model.type.UnknownTypeException
    6.45 + * @since 1.7
    6.46 + */
    6.47 +public class UnknownEntityException extends RuntimeException {
    6.48 +
    6.49 +    private static final long serialVersionUID = 269L;
    6.50 +
    6.51 +    /**
    6.52 +     * Creates a new {@code UnknownEntityException} with the specified
    6.53 +     * detail message.
    6.54 +     *
    6.55 +     * @param message the detail message
    6.56 +     */
    6.57 +    protected UnknownEntityException(String message) {
    6.58 +        super(message);
    6.59 +    }
    6.60 +}
     7.1 --- a/src/share/classes/javax/lang/model/element/UnknownAnnotationValueException.java	Fri Feb 06 09:44:58 2009 -0800
     7.2 +++ b/src/share/classes/javax/lang/model/element/UnknownAnnotationValueException.java	Fri Feb 06 17:24:04 2009 -0800
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * Copyright 2005-2009 Sun Microsystems, Inc.  All Rights Reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -25,6 +25,8 @@
    7.11  
    7.12  package javax.lang.model.element;
    7.13  
    7.14 +import javax.lang.model.UnknownEntityException;
    7.15 +
    7.16  /**
    7.17   * Indicates that an unknown kind of annotation value was encountered.
    7.18   * This can occur if the language evolves and new kinds of annotation
    7.19 @@ -39,7 +41,7 @@
    7.20   * @see AnnotationValueVisitor#visitUnknown
    7.21   * @since 1.6
    7.22   */
    7.23 -public class UnknownAnnotationValueException extends RuntimeException {
    7.24 +public class UnknownAnnotationValueException extends UnknownEntityException {
    7.25  
    7.26      private static final long serialVersionUID = 269L;
    7.27  
     8.1 --- a/src/share/classes/javax/lang/model/element/UnknownElementException.java	Fri Feb 06 09:44:58 2009 -0800
     8.2 +++ b/src/share/classes/javax/lang/model/element/UnknownElementException.java	Fri Feb 06 17:24:04 2009 -0800
     8.3 @@ -1,5 +1,5 @@
     8.4  /*
     8.5 - * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     8.6 + * Copyright 2005-2009 Sun Microsystems, Inc.  All Rights Reserved.
     8.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.8   *
     8.9   * This code is free software; you can redistribute it and/or modify it
    8.10 @@ -25,6 +25,8 @@
    8.11  
    8.12  package javax.lang.model.element;
    8.13  
    8.14 +import javax.lang.model.UnknownEntityException;
    8.15 +
    8.16  /**
    8.17   * Indicates that an unknown kind of element was encountered.  This
    8.18   * can occur if the language evolves and new kinds of elements are
    8.19 @@ -38,7 +40,7 @@
    8.20   * @see ElementVisitor#visitUnknown
    8.21   * @since 1.6
    8.22   */
    8.23 -public class UnknownElementException extends RuntimeException {
    8.24 +public class UnknownElementException extends UnknownEntityException {
    8.25  
    8.26      private static final long serialVersionUID = 269L;
    8.27  
     9.1 --- a/src/share/classes/javax/lang/model/type/UnknownTypeException.java	Fri Feb 06 09:44:58 2009 -0800
     9.2 +++ b/src/share/classes/javax/lang/model/type/UnknownTypeException.java	Fri Feb 06 17:24:04 2009 -0800
     9.3 @@ -1,5 +1,5 @@
     9.4  /*
     9.5 - * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     9.6 + * Copyright 2005-2009 Sun Microsystems, Inc.  All Rights Reserved.
     9.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.8   *
     9.9   * This code is free software; you can redistribute it and/or modify it
    9.10 @@ -25,6 +25,8 @@
    9.11  
    9.12  package javax.lang.model.type;
    9.13  
    9.14 +import javax.lang.model.UnknownEntityException;
    9.15 +
    9.16  /**
    9.17   * Indicates that an unknown kind of type was encountered.  This can
    9.18   * occur if the language evolves and new kinds of types are added to
    9.19 @@ -38,7 +40,7 @@
    9.20   * @see TypeVisitor#visitUnknown
    9.21   * @since 1.6
    9.22   */
    9.23 -public class UnknownTypeException extends RuntimeException {
    9.24 +public class UnknownTypeException extends UnknownEntityException {
    9.25  
    9.26      private static final long serialVersionUID = 269L;
    9.27  
    10.1 --- a/test/tools/javac/6304921/T6304921.out	Fri Feb 06 09:44:58 2009 -0800
    10.2 +++ b/test/tools/javac/6304921/T6304921.out	Fri Feb 06 17:24:04 2009 -0800
    10.3 @@ -7,12 +7,7 @@
    10.4  required: java.util.List<java.lang.Integer>
    10.5          List<Integer> list = new ArrayList();
    10.6                               ^
    10.7 -T6304921.java:445/445/453: warning: [fallthrough] possible fall-through into case
    10.8 -        default:
    10.9 -        ^
   10.10 -T6304921.java:522/613/614: warning: [finally] finally clause cannot complete normally
   10.11 -        }
   10.12 -        ^
   10.13 +error: warnings found and -Werror specified
   10.14  T6304921.java:727/733/737: cannot find symbol
   10.15  symbol  : variable orr
   10.16  location: class java.lang.System
   10.17 @@ -21,5 +16,5 @@
   10.18  T6304921.java:812/816/822: operator + cannot be applied to int,boolean
   10.19          return 123 + true; // bad binary expression
   10.20                     ^
   10.21 -2 errors
   10.22 -4 warnings
   10.23 +3 errors
   10.24 +2 warnings
    11.1 --- a/test/tools/javac/6758789/T6758789b.out	Fri Feb 06 09:44:58 2009 -0800
    11.2 +++ b/test/tools/javac/6758789/T6758789b.out	Fri Feb 06 17:24:04 2009 -0800
    11.3 @@ -1,3 +1,5 @@
    11.4  T6758789b.java:39:11: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<X>
    11.5  T6758789b.java:39:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo<X>, T6758789a.Foo, kindname.class, T6758789a
    11.6 +- compiler.err.warnings.and.werror
    11.7 +1 error
    11.8  2 warnings
    12.1 --- a/test/tools/javac/T6241723.out	Fri Feb 06 09:44:58 2009 -0800
    12.2 +++ b/test/tools/javac/T6241723.out	Fri Feb 06 17:24:04 2009 -0800
    12.3 @@ -2,4 +2,6 @@
    12.4  T6241723.java:23:7: compiler.warn.has.been.deprecated: A2.A21, A2
    12.5  T6241723.java:26:5: compiler.warn.has.been.deprecated: Z1, unnamed package
    12.6  T6241723.java:28:7: compiler.warn.has.been.deprecated: Z2.Z21, Z2
    12.7 +- compiler.err.warnings.and.werror
    12.8 +1 error
    12.9  4 warnings
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/T6595666.java	Fri Feb 06 17:24:04 2009 -0800
    13.3 @@ -0,0 +1,68 @@
    13.4 +/*
    13.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   13.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   13.24 + * have any questions.
   13.25 + */
   13.26 +
   13.27 +/*
   13.28 + * @test
   13.29 + * @bug 6595666
   13.30 + * @summary fix -Werror
   13.31 + */
   13.32 +
   13.33 +import java.io.*;
   13.34 +import java.util.*;
   13.35 +
   13.36 +public class T6595666 {
   13.37 +    void m() {
   13.38 +        // the following line must create warnings with -Xlint, because of unchecked conversion
   13.39 +        List<Integer> list = new ArrayList();
   13.40 +    }
   13.41 +
   13.42 +    public static void main(String... args) throws Exception {
   13.43 +        File testSrc = new File(System.getProperty("test.src", "."));
   13.44 +
   13.45 +        String basename = T6595666.class.getName();
   13.46 +        File srcFile = new File(testSrc, basename+".java");
   13.47 +        File classFile = new File(basename+".class");
   13.48 +        classFile.delete();
   13.49 +        if (classFile.exists())
   13.50 +            throw new Exception("setup error, can't delete " + classFile);
   13.51 +
   13.52 +        compile(1, "-d", ".", "-Xlint", "-Werror", srcFile.getPath());
   13.53 +        if (classFile.exists())
   13.54 +            throw new Exception("failed: found " + classFile);
   13.55 +
   13.56 +        compile(0, "-d", ".", "-Xlint", srcFile.getPath());
   13.57 +        if (!classFile.exists())
   13.58 +            throw new Exception("failed: " + classFile + " not found");
   13.59 +    }
   13.60 +
   13.61 +    private static void compile(int rc, String... args) throws Exception {
   13.62 +        System.err.println("compile: " + Arrays.asList(args));
   13.63 +        StringWriter sw = new StringWriter();
   13.64 +        PrintWriter pw = new PrintWriter(sw);
   13.65 +        int rc2 = com.sun.tools.javac.Main.compile(args, pw);
   13.66 +        pw.close();
   13.67 +        System.err.println(sw);
   13.68 +        if (rc != rc2)
   13.69 +            throw new Exception("bad exit code; expected " + rc + ", found " + rc2);
   13.70 +    }
   13.71 +}
    14.1 --- a/test/tools/javac/depDocComment/DeprecatedDocComment.out	Fri Feb 06 09:44:58 2009 -0800
    14.2 +++ b/test/tools/javac/depDocComment/DeprecatedDocComment.out	Fri Feb 06 17:24:04 2009 -0800
    14.3 @@ -1,4 +1,6 @@
    14.4  DeprecatedDocComment.java:27:28: compiler.warn.has.been.deprecated: deprecatedTest1(), DeprecatedDocComment2
    14.5  DeprecatedDocComment.java:31:28: compiler.warn.has.been.deprecated: deprecatedTest5(), DeprecatedDocComment2
    14.6  DeprecatedDocComment.java:32:28: compiler.warn.has.been.deprecated: deprecatedTest6(), DeprecatedDocComment2
    14.7 +- compiler.err.warnings.and.werror
    14.8 +1 error
    14.9  3 warnings
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/tools/javac/processing/model/TestExceptions.java	Fri Feb 06 17:24:04 2009 -0800
    15.3 @@ -0,0 +1,55 @@
    15.4 +/*
    15.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + *
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.
   15.11 + *
   15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.15 + * version 2 for more details (a copy is included in the LICENSE file that
   15.16 + * accompanied this code).
   15.17 + *
   15.18 + * You should have received a copy of the GNU General Public License version
   15.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.21 + *
   15.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   15.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   15.24 + * have any questions.
   15.25 + */
   15.26 +
   15.27 +/*
   15.28 + * @test
   15.29 + * @bug 6794071
   15.30 + * @summary Test that exceptions have a proper parent class
   15.31 + * @author  Joseph D. Darcy
   15.32 + */
   15.33 +
   15.34 +import javax.lang.model.UnknownEntityException;
   15.35 +import javax.lang.model.element.*;
   15.36 +import javax.lang.model.type.*;
   15.37 +
   15.38 +/*
   15.39 + * Verify UnknownFooExceptions can be caught with a common parent
   15.40 + * exception.
   15.41 + */
   15.42 +public class TestExceptions {
   15.43 +    public static void main(String... args) {
   15.44 +        RuntimeException[] exceptions = {
   15.45 +            new UnknownElementException((Element)null, (Object)null),
   15.46 +            new UnknownAnnotationValueException((AnnotationValue) null, (Object) null),
   15.47 +            new UnknownTypeException((TypeMirror)null, (Object)null)
   15.48 +        };
   15.49 +
   15.50 +        for(RuntimeException exception : exceptions) {
   15.51 +            try {
   15.52 +                throw exception;
   15.53 +            } catch (UnknownEntityException uee) {
   15.54 +                ;
   15.55 +            }
   15.56 +        }
   15.57 +    }
   15.58 +}

mercurial