8174839: javadoc crashes with a method which does not override a super.
Reviewed-by: jjg
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Wed Feb 15 14:12:29 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Configuration.java Wed Feb 15 14:25:50 2017 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -32,7 +32,6 @@
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.SimpleElementVisitor9;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
@@ -1116,7 +1115,7 @@
@Override
public String toString() {
- return names.toString();
+ return Arrays.toString(names);
}
@Override
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Wed Feb 15 14:12:29 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Wed Feb 15 14:25:50 2017 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -46,7 +46,6 @@
import javax.lang.model.util.Elements;
import javax.tools.FileObject;
import javax.tools.JavaFileManager.Location;
-import javax.tools.JavaFileObject;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.JavacTask;
@@ -62,7 +61,6 @@
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
import com.sun.tools.javac.code.Symbol.PackageSymbol;
import com.sun.tools.javac.code.Symbol.VarSymbol;
-import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.model.JavacElements;
@@ -297,6 +295,33 @@
return null;
}
+ // TODO: the method jx.l.m.Elements::overrides does not check
+ // the return type, see JDK-8174840 until that is resolved,
+ // use a copy of the same method, with a return type check.
+
+ // Note: the rider.overrides call in this method *must* be consistent
+ // with the call in overrideType(....), the method above.
+ public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) {
+ MethodSymbol rider = (MethodSymbol)e1;
+ MethodSymbol ridee = (MethodSymbol)e2;
+ ClassSymbol origin = (ClassSymbol)cls;
+
+ return rider.name == ridee.name &&
+
+ // not reflexive as per JLS
+ rider != ridee &&
+
+ // we don't care if ridee is static, though that wouldn't
+ // compile
+ !rider.isStatic() &&
+
+ // Symbol.overrides assumes the following
+ ridee.isMemberOf(origin, toolEnv.getTypes()) &&
+
+ // check access, signatures and check return types
+ rider.overrides(ridee, origin, toolEnv.getTypes(), true);
+ }
+
// TODO: jx.l.m ?
public Location getLocationForModule(ModuleElement mdle) {
ModuleSymbol msym = (ModuleSymbol)mdle;
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Wed Feb 15 14:12:29 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Wed Feb 15 14:25:50 2017 -0800
@@ -893,7 +893,7 @@
}
List<? extends Element> methods = te.getEnclosedElements();
for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
- if (elementUtils.overrides(method, ee, origin)) {
+ if (configuration.workArounds.overrides(method, ee, origin)) {
return ee;
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testOverridenMethods/TestBadOverride.java Wed Feb 15 14:25:50 2017 -0800
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8174839
+ * @summary Bad overriding method should not crash
+ * @library ../lib
+ * @modules jdk.javadoc/jdk.javadoc.internal.tool
+ * @build JavadocTester
+ * @run main TestBadOverride
+ */
+
+public class TestBadOverride extends JavadocTester {
+
+ /**
+ * The entry point of the test.
+ * @param args the array of command line arguments.
+ */
+ public static void main(String... args) throws Exception {
+ TestBadOverride tester = new TestBadOverride();
+ tester.runTests();
+ }
+
+ @Test
+ void test() {
+ javadoc("-d", "out",
+ "-sourcepath", testSrc,
+ "pkg4");
+ checkExit(Exit.OK);
+
+ checkOutput("pkg4/Foo.html", true,
+ "<li class=\"blockList\">\n"
+ + "<h4>toString</h4>\n"
+ + "<pre>public void toString()</pre>\n"
+ + "<div class=\"block\">Why can't I do this ?</div>\n"
+ + "</li>");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testOverridenMethods/pkg4/Foo.java Wed Feb 15 14:25:50 2017 -0800
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg4;
+
+public class Foo {
+ /**
+ * Why can't I do this ?
+ */
+ public void toString() {}
+}