8006224: Doclint NPE for attribute with no value
authorjjg
Tue, 15 Jan 2013 13:03:11 -0800
changeset 15359 a73dcb8dcbae
parent 15358 e6a64947d91e
child 15360 450af2a9e3c9
8006224: Doclint NPE for attribute with no value Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/doclint/Checker.java
langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties
langtools/test/tools/doclint/AnchorTest.java
langtools/test/tools/doclint/AnchorTest.out
--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Jan 15 20:38:39 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Jan 15 13:03:11 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -447,14 +447,18 @@
                         if (currTag != HtmlTag.A) {
                             break;
                         }
-                    // fallthrough
+                        // fallthrough
                     case ID:
                         String value = getAttrValue(tree);
-                        if (!validName.matcher(value).matches()) {
-                            env.messages.error(HTML, tree, "dc.invalid.anchor", value);
-                        }
-                        if (!foundAnchors.add(value)) {
-                            env.messages.error(HTML, tree, "dc.anchor.already.defined", value);
+                        if (value == null) {
+                            env.messages.error(HTML, tree, "dc.anchor.value.missing");
+                        } else {
+                            if (!validName.matcher(value).matches()) {
+                                env.messages.error(HTML, tree, "dc.invalid.anchor", value);
+                            }
+                            if (!foundAnchors.add(value)) {
+                                env.messages.error(HTML, tree, "dc.anchor.already.defined", value);
+                            }
                         }
                         break;
 
--- a/langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties	Tue Jan 15 20:38:39 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties	Tue Jan 15 13:03:11 2013 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 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
@@ -24,6 +24,7 @@
 #
 
 dc.anchor.already.defined = anchor already defined: {0}
+dc.anchor.value.missing = no value given for anchor
 dc.attr.lacks.value = attribute lacks value
 dc.attr.obsolete = attribute obsolete: {0}
 dc.attr.obsolete.use.css = attribute obsolete, use CSS instead: {0}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/AnchorTest.java	Tue Jan 15 13:03:11 2013 -0800
@@ -0,0 +1,93 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8004832
+ * @summary Add new doclint package
+ * @build DocLintTester
+ * @run main DocLintTester -ref AnchorTest.out AnchorTest.java
+ */
+
+/** */
+public class AnchorTest {
+    // tests for <a name=value>
+
+    /**
+     * <a name=foo></a>
+     */
+    public void a_name_foo() { }
+
+    /**
+     * <a name=foo></a>
+     */
+    public void a_name_already_defined() { }
+
+    /**
+     * <a name=></a>
+     */
+    public void a_name_empty() { }
+
+    /**
+     * <a name=123 ></a>
+     */
+    public void a_name_invalid() { }
+
+    /**
+     * <a name ></a>
+     */
+    public void a_name_missing() { }
+
+    // tests for <a id=value>
+
+    /**
+     * <a id=a_id_foo></a>
+     */
+    public void a_id_foo() { }
+
+    /**
+     * <a id=foo></a>
+     */
+    public void a_id_already_defined() { }
+
+    /**
+     * <a id=></a>
+     */
+    public void a_id_empty() { }
+
+    /**
+     * <a id=123 ></a>
+     */
+    public void a_id_invalid() { }
+
+    /**
+     * <a id ></a>
+     */
+    public void a_id_missing() { }
+
+    // tests for id=value on non-<a> tags
+
+    /**
+     * <p id=p_id_foo>text</p>
+     */
+    public void p_id_foo() { }
+
+    /**
+     * <p id=foo>text</p>
+     */
+    public void p_id_already_defined() { }
+
+    /**
+     * <p id=>text</p>
+     */
+    public void p_id_empty() { }
+
+    /**
+     * <p id=123 >text</p>
+     */
+    public void p_id_invalid() { }
+
+    /**
+     * <p id >text</p>
+     */
+    public void p_id_missing() { }
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/AnchorTest.out	Tue Jan 15 13:03:11 2013 -0800
@@ -0,0 +1,37 @@
+AnchorTest.java:19: error: anchor already defined: foo
+     * <a name=foo></a>
+          ^
+AnchorTest.java:24: error: invalid name for anchor: ""
+     * <a name=></a>
+          ^
+AnchorTest.java:29: error: invalid name for anchor: "123"
+     * <a name=123 ></a>
+          ^
+AnchorTest.java:34: error: no value given for anchor
+     * <a name ></a>
+          ^
+AnchorTest.java:46: error: anchor already defined: foo
+     * <a id=foo></a>
+          ^
+AnchorTest.java:51: error: invalid name for anchor: ""
+     * <a id=></a>
+          ^
+AnchorTest.java:56: error: invalid name for anchor: "123"
+     * <a id=123 ></a>
+          ^
+AnchorTest.java:61: error: no value given for anchor
+     * <a id ></a>
+          ^
+AnchorTest.java:73: error: anchor already defined: foo
+     * <p id=foo>text</p>
+          ^
+AnchorTest.java:78: error: invalid name for anchor: ""
+     * <p id=>text</p>
+          ^
+AnchorTest.java:83: error: invalid name for anchor: "123"
+     * <p id=123 >text</p>
+          ^
+AnchorTest.java:88: error: no value given for anchor
+     * <p id >text</p>
+          ^
+12 errors