提交 6ad85204 编写于 作者: J jjg

8006224: Doclint NPE for attribute with no value

Reviewed-by: darcy
上级 e4892d55
/*
* 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 @@ public class Checker extends DocTreeScanner<Void, Void> {
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;
......
#
# 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}
......
/*
* @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() { }
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册