From d46936ac8d4da515d699a597a8af21c3dc511d9d Mon Sep 17 00:00:00 2001 From: jjg Date: Wed, 24 Jul 2013 17:35:42 -0700 Subject: [PATCH] 8020556: doclint does not check type variables for @throws Reviewed-by: mcimadamore --- .../classes/com/sun/source/util/DocTrees.java | 1 - .../classes/com/sun/tools/doclint/Checker.java | 12 ++++++++++-- .../com/sun/tools/javac/api/JavacTrees.java | 17 +++++++++-------- .../classes/com/sun/tools/javac/comp/Env.java | 13 +++++++++++-- test/tools/doclint/ReferenceTest.java | 8 +++++++- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/share/classes/com/sun/source/util/DocTrees.java b/src/share/classes/com/sun/source/util/DocTrees.java index affc5f3a..cd23e78e 100644 --- a/src/share/classes/com/sun/source/util/DocTrees.java +++ b/src/share/classes/com/sun/source/util/DocTrees.java @@ -30,7 +30,6 @@ import javax.lang.model.element.Element; import javax.tools.JavaCompiler.CompilationTask; import com.sun.source.doctree.DocCommentTree; -import com.sun.source.doctree.ReferenceTree; import javax.tools.Diagnostic; /** diff --git a/src/share/classes/com/sun/tools/doclint/Checker.java b/src/share/classes/com/sun/tools/doclint/Checker.java index 9b75c83a..d7d8ada4 100644 --- a/src/share/classes/com/sun/tools/doclint/Checker.java +++ b/src/share/classes/com/sun/tools/doclint/Checker.java @@ -753,8 +753,7 @@ public class Checker extends DocTreePathScanner { Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); - } else if (ex.asType().getKind() == TypeKind.DECLARED - && env.types.isAssignable(ex.asType(), env.java_lang_Throwable)) { + } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: @@ -773,6 +772,15 @@ public class Checker extends DocTreePathScanner { return scan(tree.getDescription(), ignore); } + private boolean isThrowable(TypeMirror tm) { + switch (tm.getKind()) { + case DECLARED: + case TYPEVAR: + return env.types.isAssignable(tm, env.java_lang_Throwable); + } + return false; + } + private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List list) { boolean found = false; for (TypeMirror tl : list) { diff --git a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java index ef03f718..fc8fbe65 100644 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java @@ -69,7 +69,6 @@ import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ErrorType; import com.sun.tools.javac.code.Type.UnionClassType; import com.sun.tools.javac.code.Types; -import com.sun.tools.javac.code.TypeTag; import com.sun.tools.javac.code.Types.TypeRelation; import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.AttrContext; @@ -358,7 +357,7 @@ public class JavacTrees extends DocTrees { Log.DeferredDiagnosticHandler deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); try { - final ClassSymbol tsym; + final TypeSymbol tsym; final Name memberName; if (ref.qualifierExpression == null) { tsym = env.enclClass.sym; @@ -387,7 +386,7 @@ public class JavacTrees extends DocTrees { return null; } } else { - tsym = (ClassSymbol) t.tsym; + tsym = t.tsym; memberName = ref.memberName; } } @@ -408,15 +407,17 @@ public class JavacTrees extends DocTrees { paramTypes = lb.toList(); } - Symbol msym = (memberName == tsym.name) - ? findConstructor(tsym, paramTypes) - : findMethod(tsym, memberName, paramTypes); + ClassSymbol sym = (ClassSymbol) types.upperBound(tsym.type).tsym; + + Symbol msym = (memberName == sym.name) + ? findConstructor(sym, paramTypes) + : findMethod(sym, memberName, paramTypes); if (paramTypes != null) { // explicit (possibly empty) arg list given, so cannot be a field return msym; } - VarSymbol vsym = (ref.paramTypes != null) ? null : findField(tsym, memberName); + VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName); // prefer a field over a method with no parameters if (vsym != null && (msym == null || @@ -789,6 +790,7 @@ public class JavacTrees extends DocTrees { case METHOD: // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); method = (JCMethodDecl)tree; + env = memberEnter.getMethodEnv(method, env); break; case VARIABLE: // System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); @@ -800,7 +802,6 @@ public class JavacTrees extends DocTrees { try { Assert.check(method.body == tree); method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); - env = memberEnter.getMethodEnv(method, env); env = attribStatToTree(method.body, env, copier.leafCopy); } finally { method.body = (JCBlock) tree; diff --git a/src/share/classes/com/sun/tools/javac/comp/Env.java b/src/share/classes/com/sun/tools/javac/comp/Env.java index c788055d..fc200a9b 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Env.java +++ b/src/share/classes/com/sun/tools/javac/comp/Env.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -124,7 +124,16 @@ public class Env implements Iterable> { @Override public String toString() { - return "Env[" + info + (outer == null ? "" : ",outer=" + outer) + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("Env[").append(info); +// if (enclMethod != null) +// sb.append(",enclMethod=").append(Pretty.toSimpleString(enclMethod)); +// if (enclClass != null) +// sb.append(",enclClass=").append(Pretty.toSimpleString(enclClass)); + if (outer != null) + sb.append(",outer=").append(outer); + sb.append("]"); + return sb.toString(); } public Iterator> iterator() { diff --git a/test/tools/doclint/ReferenceTest.java b/test/tools/doclint/ReferenceTest.java index e25c56c3..57b26aef 100644 --- a/test/tools/doclint/ReferenceTest.java +++ b/test/tools/doclint/ReferenceTest.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8004832 + * @bug 8004832 8020556 * @summary Add new doclint package * @build DocLintTester * @run main DocLintTester -Xmsgs:-reference ReferenceTest.java @@ -48,5 +48,11 @@ public class ReferenceTest { * @throws Exception description */ public void exception_not_thrown() { } + + /** + * @param throwable + * @throws T description + */ + public void valid_throws_generic() throws T { } } -- GitLab