src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java
changeset 48721 ef3557eb4306
parent 48054 702043a4cdeb
child 50468 4a5fd709e286
equal deleted inserted replaced
48720:290b480df13e 48721:ef3557eb4306
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    36 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    36 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    37 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
    37 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
    38 import com.sun.tools.javac.tree.*;
    38 import com.sun.tools.javac.tree.*;
    39 import com.sun.tools.javac.util.*;
    39 import com.sun.tools.javac.util.*;
    40 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    40 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
       
    41 import com.sun.tools.javac.util.JCDiagnostic.Error;
       
    42 import com.sun.tools.javac.util.JCDiagnostic.Warning;
    41 
    43 
    42 import com.sun.tools.javac.code.Symbol.*;
    44 import com.sun.tools.javac.code.Symbol.*;
    43 import com.sun.tools.javac.tree.JCTree.*;
    45 import com.sun.tools.javac.tree.JCTree.*;
    44 
    46 
    45 import static com.sun.tools.javac.code.Flags.*;
    47 import static com.sun.tools.javac.code.Flags.*;
  1181                 // unchecked exception, the result list would not be empty, as the augmented
  1183                 // unchecked exception, the result list would not be empty, as the augmented
  1182                 // thrown set includes { RuntimeException, Error }; if 'exc' was a checked
  1184                 // thrown set includes { RuntimeException, Error }; if 'exc' was a checked
  1183                 // exception, that would have been covered in the branch above
  1185                 // exception, that would have been covered in the branch above
  1184                 if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty() &&
  1186                 if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty() &&
  1185                         !isExceptionOrThrowable(exc)) {
  1187                         !isExceptionOrThrowable(exc)) {
  1186                     String key = catchableThrownTypes.length() == 1 ?
  1188                     Warning key = catchableThrownTypes.length() == 1 ?
  1187                             "unreachable.catch" :
  1189                             Warnings.UnreachableCatch(catchableThrownTypes) :
  1188                             "unreachable.catch.1";
  1190                             Warnings.UnreachableCatch1(catchableThrownTypes);
  1189                     log.warning(pos, key, catchableThrownTypes);
  1191                     log.warning(pos, key);
  1190                 }
  1192                 }
  1191             }
  1193             }
  1192         }
  1194         }
  1193         //where
  1195         //where
  1194             private boolean isExceptionOrThrowable(Type exc) {
  1196             private boolean isExceptionOrThrowable(Type exc) {
  1615                         else {
  1617                         else {
  1616                             log.error(pos,
  1618                             log.error(pos,
  1617                                       Errors.FinalParameterMayNotBeAssigned(sym));
  1619                                       Errors.FinalParameterMayNotBeAssigned(sym));
  1618                         }
  1620                         }
  1619                     } else if (!uninits.isMember(sym.adr)) {
  1621                     } else if (!uninits.isMember(sym.adr)) {
  1620                         log.error(pos, flowKind.errKey, sym);
  1622                         log.error(pos, diags.errorKey(flowKind.errKey, sym));
  1621                     } else {
  1623                     } else {
  1622                         uninit(sym);
  1624                         uninit(sym);
  1623                     }
  1625                     }
  1624                 }
  1626                 }
  1625                 inits.incl(sym.adr);
  1627                 inits.incl(sym.adr);
  1654         }
  1656         }
  1655 
  1657 
  1656         /** Check that trackable variable is initialized.
  1658         /** Check that trackable variable is initialized.
  1657          */
  1659          */
  1658         void checkInit(DiagnosticPosition pos, VarSymbol sym) {
  1660         void checkInit(DiagnosticPosition pos, VarSymbol sym) {
  1659             checkInit(pos, sym, "var.might.not.have.been.initialized");
  1661             checkInit(pos, sym, Errors.VarMightNotHaveBeenInitialized(sym));
  1660         }
  1662         }
  1661 
  1663 
  1662         void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) {
  1664         void checkInit(DiagnosticPosition pos, VarSymbol sym, Error errkey) {
  1663             if ((sym.adr >= firstadr || sym.owner.kind != TYP) &&
  1665             if ((sym.adr >= firstadr || sym.owner.kind != TYP) &&
  1664                 trackable(sym) &&
  1666                 trackable(sym) &&
  1665                 !inits.isMember(sym.adr)) {
  1667                 !inits.isMember(sym.adr)) {
  1666                 log.error(pos, errkey, sym);
  1668                 log.error(pos, errkey);
  1667                 inits.incl(sym.adr);
  1669                 inits.incl(sym.adr);
  1668             }
  1670             }
  1669         }
  1671         }
  1670 
  1672 
  1671         /** Utility method to reset several Bits instances.
  1673         /** Utility method to reset several Bits instances.
  1892                             if (var.owner == classDef.sym) {
  1894                             if (var.owner == classDef.sym) {
  1893                                 // choose the diagnostic position based on whether
  1895                                 // choose the diagnostic position based on whether
  1894                                 // the ctor is default(synthesized) or not
  1896                                 // the ctor is default(synthesized) or not
  1895                                 if (isSynthesized) {
  1897                                 if (isSynthesized) {
  1896                                     checkInit(TreeInfo.diagnosticPositionFor(var, vardecl),
  1898                                     checkInit(TreeInfo.diagnosticPositionFor(var, vardecl),
  1897                                         var, "var.not.initialized.in.default.constructor");
  1899                                         var, Errors.VarNotInitializedInDefaultConstructor(var));
  1898                                 } else {
  1900                                 } else {
  1899                                     checkInit(TreeInfo.diagEndPos(tree.body), var);
  1901                                     checkInit(TreeInfo.diagEndPos(tree.body), var);
  1900                                 }
  1902                                 }
  1901                             }
  1903                             }
  1902                         }
  1904                         }