Wed, 24 Jul 2013 17:35:42 -0700
8020556: doclint does not check type variables for @throws
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/source/util/DocTrees.java Tue Jul 23 20:42:54 2013 -0400 1.2 +++ b/src/share/classes/com/sun/source/util/DocTrees.java Wed Jul 24 17:35:42 2013 -0700 1.3 @@ -30,7 +30,6 @@ 1.4 import javax.tools.JavaCompiler.CompilationTask; 1.5 1.6 import com.sun.source.doctree.DocCommentTree; 1.7 -import com.sun.source.doctree.ReferenceTree; 1.8 import javax.tools.Diagnostic; 1.9 1.10 /**
2.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java Tue Jul 23 20:42:54 2013 -0400 2.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Wed Jul 24 17:35:42 2013 -0700 2.3 @@ -753,8 +753,7 @@ 2.4 Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); 2.5 if (ex == null) { 2.6 env.messages.error(REFERENCE, tree, "dc.ref.not.found"); 2.7 - } else if (ex.asType().getKind() == TypeKind.DECLARED 2.8 - && env.types.isAssignable(ex.asType(), env.java_lang_Throwable)) { 2.9 + } else if (isThrowable(ex.asType())) { 2.10 switch (env.currElement.getKind()) { 2.11 case CONSTRUCTOR: 2.12 case METHOD: 2.13 @@ -773,6 +772,15 @@ 2.14 return scan(tree.getDescription(), ignore); 2.15 } 2.16 2.17 + private boolean isThrowable(TypeMirror tm) { 2.18 + switch (tm.getKind()) { 2.19 + case DECLARED: 2.20 + case TYPEVAR: 2.21 + return env.types.isAssignable(tm, env.java_lang_Throwable); 2.22 + } 2.23 + return false; 2.24 + } 2.25 + 2.26 private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) { 2.27 boolean found = false; 2.28 for (TypeMirror tl : list) {
3.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Tue Jul 23 20:42:54 2013 -0400 3.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Wed Jul 24 17:35:42 2013 -0700 3.3 @@ -69,7 +69,6 @@ 3.4 import com.sun.tools.javac.code.Type.ErrorType; 3.5 import com.sun.tools.javac.code.Type.UnionClassType; 3.6 import com.sun.tools.javac.code.Types; 3.7 -import com.sun.tools.javac.code.TypeTag; 3.8 import com.sun.tools.javac.code.Types.TypeRelation; 3.9 import com.sun.tools.javac.comp.Attr; 3.10 import com.sun.tools.javac.comp.AttrContext; 3.11 @@ -358,7 +357,7 @@ 3.12 Log.DeferredDiagnosticHandler deferredDiagnosticHandler = 3.13 new Log.DeferredDiagnosticHandler(log); 3.14 try { 3.15 - final ClassSymbol tsym; 3.16 + final TypeSymbol tsym; 3.17 final Name memberName; 3.18 if (ref.qualifierExpression == null) { 3.19 tsym = env.enclClass.sym; 3.20 @@ -387,7 +386,7 @@ 3.21 return null; 3.22 } 3.23 } else { 3.24 - tsym = (ClassSymbol) t.tsym; 3.25 + tsym = t.tsym; 3.26 memberName = ref.memberName; 3.27 } 3.28 } 3.29 @@ -408,15 +407,17 @@ 3.30 paramTypes = lb.toList(); 3.31 } 3.32 3.33 - Symbol msym = (memberName == tsym.name) 3.34 - ? findConstructor(tsym, paramTypes) 3.35 - : findMethod(tsym, memberName, paramTypes); 3.36 + ClassSymbol sym = (ClassSymbol) types.upperBound(tsym.type).tsym; 3.37 + 3.38 + Symbol msym = (memberName == sym.name) 3.39 + ? findConstructor(sym, paramTypes) 3.40 + : findMethod(sym, memberName, paramTypes); 3.41 if (paramTypes != null) { 3.42 // explicit (possibly empty) arg list given, so cannot be a field 3.43 return msym; 3.44 } 3.45 3.46 - VarSymbol vsym = (ref.paramTypes != null) ? null : findField(tsym, memberName); 3.47 + VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName); 3.48 // prefer a field over a method with no parameters 3.49 if (vsym != null && 3.50 (msym == null || 3.51 @@ -789,6 +790,7 @@ 3.52 case METHOD: 3.53 // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); 3.54 method = (JCMethodDecl)tree; 3.55 + env = memberEnter.getMethodEnv(method, env); 3.56 break; 3.57 case VARIABLE: 3.58 // System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); 3.59 @@ -800,7 +802,6 @@ 3.60 try { 3.61 Assert.check(method.body == tree); 3.62 method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); 3.63 - env = memberEnter.getMethodEnv(method, env); 3.64 env = attribStatToTree(method.body, env, copier.leafCopy); 3.65 } finally { 3.66 method.body = (JCBlock) tree;
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Env.java Tue Jul 23 20:42:54 2013 -0400 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Env.java Wed Jul 24 17:35:42 2013 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -124,7 +124,16 @@ 4.11 4.12 @Override 4.13 public String toString() { 4.14 - return "Env[" + info + (outer == null ? "" : ",outer=" + outer) + "]"; 4.15 + StringBuilder sb = new StringBuilder(); 4.16 + sb.append("Env[").append(info); 4.17 +// if (enclMethod != null) 4.18 +// sb.append(",enclMethod=").append(Pretty.toSimpleString(enclMethod)); 4.19 +// if (enclClass != null) 4.20 +// sb.append(",enclClass=").append(Pretty.toSimpleString(enclClass)); 4.21 + if (outer != null) 4.22 + sb.append(",outer=").append(outer); 4.23 + sb.append("]"); 4.24 + return sb.toString(); 4.25 } 4.26 4.27 public Iterator<Env<A>> iterator() {
5.1 --- a/test/tools/doclint/ReferenceTest.java Tue Jul 23 20:42:54 2013 -0400 5.2 +++ b/test/tools/doclint/ReferenceTest.java Wed Jul 24 17:35:42 2013 -0700 5.3 @@ -1,6 +1,6 @@ 5.4 /* 5.5 * @test /nodynamiccopyright/ 5.6 - * @bug 8004832 5.7 + * @bug 8004832 8020556 5.8 * @summary Add new doclint package 5.9 * @build DocLintTester 5.10 * @run main DocLintTester -Xmsgs:-reference ReferenceTest.java 5.11 @@ -48,5 +48,11 @@ 5.12 * @throws Exception description 5.13 */ 5.14 public void exception_not_thrown() { } 5.15 + 5.16 + /** 5.17 + * @param <T> throwable 5.18 + * @throws T description 5.19 + */ 5.20 + public <T extends Throwable> void valid_throws_generic() throws T { } 5.21 } 5.22