8020556: doclint does not check type variables for @throws
authorjjg
Wed, 24 Jul 2013 17:35:42 -0700
changeset 19125 db8cab0ecbd9
parent 19124 d7f8d45d9362
child 19126 20123a84b35a
8020556: doclint does not check type variables for @throws Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/source/util/DocTrees.java
langtools/src/share/classes/com/sun/tools/doclint/Checker.java
langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java
langtools/src/share/classes/com/sun/tools/javac/comp/Env.java
langtools/test/tools/doclint/ReferenceTest.java
--- a/langtools/src/share/classes/com/sun/source/util/DocTrees.java	Tue Jul 23 20:42:54 2013 -0400
+++ b/langtools/src/share/classes/com/sun/source/util/DocTrees.java	Wed Jul 24 17:35:42 2013 -0700
@@ -30,7 +30,6 @@
 import javax.tools.JavaCompiler.CompilationTask;
 
 import com.sun.source.doctree.DocCommentTree;
-import com.sun.source.doctree.ReferenceTree;
 import javax.tools.Diagnostic;
 
 /**
--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Jul 23 20:42:54 2013 -0400
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Wed Jul 24 17:35:42 2013 -0700
@@ -753,8 +753,7 @@
         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 @@
         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<? extends TypeMirror> list) {
         boolean found = false;
         for (TypeMirror tl : list) {
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Tue Jul 23 20:42:54 2013 -0400
+++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Wed Jul 24 17:35:42 2013 -0700
@@ -69,7 +69,6 @@
 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 @@
         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 @@
                         return null;
                     }
                 } else {
-                    tsym = (ClassSymbol) t.tsym;
+                    tsym = t.tsym;
                     memberName = ref.memberName;
                 }
             }
@@ -408,15 +407,17 @@
                 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 @@
                 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 @@
                         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;
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java	Tue Jul 23 20:42:54 2013 -0400
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Env.java	Wed Jul 24 17:35:42 2013 -0700
@@ -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 @@
 
     @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<Env<A>> iterator() {
--- a/langtools/test/tools/doclint/ReferenceTest.java	Tue Jul 23 20:42:54 2013 -0400
+++ b/langtools/test/tools/doclint/ReferenceTest.java	Wed Jul 24 17:35:42 2013 -0700
@@ -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 @@
      * @throws Exception description
      */
     public void exception_not_thrown() { }
+
+    /**
+     * @param <T> throwable
+     * @throws T description
+     */
+    public <T extends Throwable> void valid_throws_generic() throws T { }
 }