1151 |
1151 |
1152 void checkCaughtType(DiagnosticPosition pos, Type exc, List<Type> thrownInTry, List<Type> caughtInTry) { |
1152 void checkCaughtType(DiagnosticPosition pos, Type exc, List<Type> thrownInTry, List<Type> caughtInTry) { |
1153 if (chk.subset(exc, caughtInTry)) { |
1153 if (chk.subset(exc, caughtInTry)) { |
1154 log.error(pos, "except.already.caught", exc); |
1154 log.error(pos, "except.already.caught", exc); |
1155 } else if (!chk.isUnchecked(pos, exc) && |
1155 } else if (!chk.isUnchecked(pos, exc) && |
1156 exc.tsym != syms.throwableType.tsym && |
1156 !isExceptionOrThrowable(exc) && |
1157 exc.tsym != syms.exceptionType.tsym && |
|
1158 !chk.intersects(exc, thrownInTry)) { |
1157 !chk.intersects(exc, thrownInTry)) { |
1159 log.error(pos, "except.never.thrown.in.try", exc); |
1158 log.error(pos, "except.never.thrown.in.try", exc); |
1160 } else if (allowImprovedCatchAnalysis) { |
1159 } else if (allowImprovedCatchAnalysis) { |
1161 List<Type> catchableThrownTypes = chk.intersect(List.of(exc), thrownInTry); |
1160 List<Type> catchableThrownTypes = chk.intersect(List.of(exc), thrownInTry); |
1162 // 'catchableThrownTypes' cannnot possibly be empty - if 'exc' was an |
1161 // 'catchableThrownTypes' cannnot possibly be empty - if 'exc' was an |
1163 // unchecked exception, the result list would not be empty, as the augmented |
1162 // unchecked exception, the result list would not be empty, as the augmented |
1164 // thrown set includes { RuntimeException, Error }; if 'exc' was a checked |
1163 // thrown set includes { RuntimeException, Error }; if 'exc' was a checked |
1165 // exception, that would have been covered in the branch above |
1164 // exception, that would have been covered in the branch above |
1166 if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty()) { |
1165 if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty() && |
|
1166 !isExceptionOrThrowable(exc)) { |
1167 String key = catchableThrownTypes.length() == 1 ? |
1167 String key = catchableThrownTypes.length() == 1 ? |
1168 "unreachable.catch" : |
1168 "unreachable.catch" : |
1169 "unreachable.catch.1"; |
1169 "unreachable.catch.1"; |
1170 log.warning(pos, key, catchableThrownTypes); |
1170 log.warning(pos, key, catchableThrownTypes); |
1171 } |
1171 } |
1172 } |
1172 } |
1173 } |
1173 } |
|
1174 //where |
|
1175 private boolean isExceptionOrThrowable(Type exc) { |
|
1176 return exc.tsym == syms.throwableType.tsym || |
|
1177 exc.tsym == syms.exceptionType.tsym; |
|
1178 } |
|
1179 |
1174 |
1180 |
1175 public void visitConditional(JCConditional tree) { |
1181 public void visitConditional(JCConditional tree) { |
1176 scanCond(tree.cond); |
1182 scanCond(tree.cond); |
1177 Bits initsBeforeElse = initsWhenFalse; |
1183 Bits initsBeforeElse = initsWhenFalse; |
1178 Bits uninitsBeforeElse = uninitsWhenFalse; |
1184 Bits uninitsBeforeElse = uninitsWhenFalse; |