# HG changeset patch # User jjg # Date 1358283791 28800 # Node ID a73dcb8dcbaefb6d0e1daff271d932111341d16c # Parent e6a64947d91ec007f996ad478a3cd42a01882e1c 8006224: Doclint NPE for attribute with no value Reviewed-by: darcy diff -r e6a64947d91e -r a73dcb8dcbae langtools/src/share/classes/com/sun/tools/doclint/Checker.java --- 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; diff -r e6a64947d91e -r a73dcb8dcbae langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties --- 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} diff -r e6a64947d91e -r a73dcb8dcbae langtools/test/tools/doclint/AnchorTest.java --- /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 + + /** + * + */ + public void a_name_foo() { } + + /** + * + */ + public void a_name_already_defined() { } + + /** + * + */ + public void a_name_empty() { } + + /** + * + */ + public void a_name_invalid() { } + + /** + * + */ + public void a_name_missing() { } + + // tests for + + /** + * + */ + public void a_id_foo() { } + + /** + * + */ + public void a_id_already_defined() { } + + /** + * + */ + public void a_id_empty() { } + + /** + * + */ + public void a_id_invalid() { } + + /** + * + */ + public void a_id_missing() { } + + // tests for id=value on non- tags + + /** + *

text

+ */ + public void p_id_foo() { } + + /** + *

text

+ */ + public void p_id_already_defined() { } + + /** + *

text

+ */ + public void p_id_empty() { } + + /** + *

text

+ */ + public void p_id_invalid() { } + + /** + *

text

+ */ + public void p_id_missing() { } + + +} diff -r e6a64947d91e -r a73dcb8dcbae langtools/test/tools/doclint/AnchorTest.out --- /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 + *
+ ^ +AnchorTest.java:24: error: invalid name for anchor: "" + * + ^ +AnchorTest.java:29: error: invalid name for anchor: "123" + * + ^ +AnchorTest.java:34: error: no value given for anchor + * + ^ +AnchorTest.java:46: error: anchor already defined: foo + * + ^ +AnchorTest.java:51: error: invalid name for anchor: "" + * + ^ +AnchorTest.java:56: error: invalid name for anchor: "123" + * + ^ +AnchorTest.java:61: error: no value given for anchor + * + ^ +AnchorTest.java:73: error: anchor already defined: foo + *

text

+ ^ +AnchorTest.java:78: error: invalid name for anchor: "" + *

text

+ ^ +AnchorTest.java:83: error: invalid name for anchor: "123" + *

text

+ ^ +AnchorTest.java:88: error: no value given for anchor + *

text

+ ^ +12 errors