http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html

Turning off doclint in JDK 8 Javadoc

 

JDK 8 includes many updates, but one is I suspect going to cause quite a few complaints - doclint for Javadoc.

Javadoc doclint

Documentation is not something most developers like writing. With Java, we were fortunate to have the Javadoc toolset built in and easy to access from day one. As such, writing Javadoc is a standard part of most developers life.

The Javadoc comments in source code use a mixture of tags, starting with @, and HTML to allow the developer to express their comment and format it nicely.

Up to JDK 7, the Javadoc tool was pretty lenient. As a developer, you could write anything that vaguely resembled HTML and the tool would rarely complain beyond warnings. Thus you could have @link references that were inaccurate (such as due to refactoring) and the tool would simply provide a warning.

With JDK 8, a new part has been added to Javadoc called doclint and it changes that friendly behaviour. In particular, the tool aim to get conforming W3C HTML 4.01 HTML (despite the fact that humans are very bad at matching conformance wrt HTML).

With JDK 8, you are unable to get Javadoc unless your tool meets the standards of doclint. Some of its rules are:

  • no self-closed HTML tags, such as <br /> or <a id="x" />
  • no unclosed HTML tags, such as <ul> without matching </ul>
  • no invalid HTML end tags, such as </br>
  • no invalid HTML attributes, based on doclint's interpretation of W3C HTML 4.01
  • no duplicate HTML id attribute
  • no empty HTML href attribute
  • no incorrectly nested headers, such as class documentation must have <h3>, not <h4>
  • no invalid HTML tags, such as List<String> (where you forgot to escape using &lt;)
  • no broken @link references
  • no broken @param references, they must match the actual parameter name
  • no broken @throws references, the first word must be a class name

Note that these are errors, not warnings. Break the rules and you get no Javadoc output.

In my opinion, this is way too strict to be the default. I have no problem with such a tool existing in Javadoc, but given the history of Javadoc, errors like this should be opt-in, not opt-out. Its far better to get slightly broken Javadoc than no Javadoc.

I also haven't been able to find a list of the rules, which makes life hard. At least we can see the source code to reverse engineer them.

Turning off doclint

The magic incantation you need is -Xdoclint:none. This goes on the command line invoking Javadoc.

If you are running from maven, you need to use the additionalparam setting, as per the manual. Either add it as a global property:

  <properties>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>

or add it to the maven-javadoc-plugin:

  <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>

Ant also uses additionalparam to pass in -Xdoclint:none, see the manual.

Gradle does not expose additionalparam but Tim Yates and Cedric Champeau advise of this solution:

  if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}

See also the Gradle manual.

Summary

I don't mind doclint existing, but there is no way that it should be turned on to error mode by default. Getting some Javadoc produced without hassle is far more important than pandering to the doclint style checks. In addition, it is very heavy handed with what it defines to be errors, rejecting plenty of HTML that works perfectly fine in a browser.

I've asked the maven team to disable doclint by default, and I'd suggest the same to Ant and Gradle. Unfortunately, the Oracle team seem convinced that they've made the right choice with errors by default and their use of strict HTML.

Comments welcome, but please note that non-specific "it didn't work for me" comments should be at Stack Overflow or Java Ranch, not here!

26 comments:

    1. How can they possibly consider this an acceptible change? Ths amount of currently valid documentation that will fail now will be immense. I know that much of my own documentation will be invalid as I write XHTML (I.e. I always close all tags). Some editors will not format Javadoc properly if the tags aren't closed.

      So now, many, possibly most, developers will turn doclint off and never turn it back on again negating its benefits.

      Reply

    2. Surely they should be enforcing a subset of HTML5, not HTML4.01?

      As all modern browsers support a fair chunk of HTML5.

      Reply

    3. I
      think it's a good thing they decided to fail-fast on invalid javadocs.
      But since when are "self-closed HTML tags, such as <br />"
      invalid?

      Reply

      Replies

       
       
    4. <br /> is invalid in HTML4, and has always been. HTML is not XML. Browsers are very lenient, of course.

      This
      stems from a complicated relationship between HTML and XHTML. An old
      but relevant article on the subject: http://hixie.ch/advocacy/xhtml

      HTML5
      fixes this issue (both <br> and <br /> are fine, among
      thousands of other such things), so it's a mystery why Javadoc insists
      on HTML4.

    5. The
      excuse they give in the docs is that they use frameset, but that excuse
      is invalid for two reasons: (1) surely even frameset works in HTML5;
      (2) even if it didn't, surely that one page with the frameset could be
      HTML4 while the rest could be HTML5.

    6.  
    7. Agreed:
      they need to support a subset of HTML 5, not HTML 4, especially since
      they fail-fast by default and HTML 4 doesn't support
      .

      But the decision to fail-fast by default on invalid input is a good decision I think.

      Reply

    8. Looks like it won't work with Maven 3.0.4, what is the minimum Maven and Java 8 build to actually accept -Xdoclint:none?

      Besides
      styling and font of Java 8 JavaDoc look extremely bad in every browser,
      even the Spec Leads of some Platform JSRs avoid it for that reason...

      Reply

      Replies

       
       
    9. I applied both in a POM and it ended up working with a Maven 3.x version and Java 8 close to Final.
      JavaDoc
      is still bad and someone from the Frontend team at Oracle shared the
      issue. The problem is, that almost every major browser shows many
      characters like "a" as an ugly, unreadable chunk (the upper part of the
      letter running into the lower one like it's melting ;-/ ) So far Firefox
      seems to handle it best, but all other browsers I checked (Chrome, IE,
      Opera) look horrible.

    10.  
    11. I've seen on StackOverflow (link)
      that with JDK8 you must now add either a caption or a summary if you
      use HTML tables inside Javadoc comments. Why would this be required?
      Isn't a <table> without a caption or a summary perfectly legal
      HTML?

      Reply

      Replies

       
       
    12. Looks
      like its an accessibility feature.
      http://www.w3schools.com/tags/att_table_summary.asp . Big corporates
      like Oracle tend to worry about such things.

    13.  
    14. There is an XML flavor of HTML 4 (but not HTML5) called XHTML 1.0, so something like
      might well be what you intended to output....

      Reply

    15. I
      wish they'd ditch HTML in favor of markdown or wiki syntax or
      something. I have to be able to read the docs in source before they get
      stuffed into a full-blown HTML page, and raw HTML is not human-friendly
      at all. I see too much un- and under-commented code as it is: all this
      does is create a disincentive to write Javadoc at all. It would make
      more sense to fail when public classes lack Javadocs entirely than to do
      what they've done.

      Reply

      Replies

       
       
    16. +1. Never gonna happen though.

    17. This is possible: http://asciidoctor.org/news/2013/06/03/asciidoclet-announcement/

    18.  
    19. -Xdoclint:none is an invalid option in pre-8 Javadoc

      javadoc: error - invalid flag: -Xdoclint:none

      Is there a backwards-compatible way to maintain the former behaviour?

      Reply

    20. I'm
      so glad they upgraded this stuff to error status. Sure, I had to fix
      140 or so cases where it was just a missing caption on a table, but it
      found 7 legit issues of broken links, incorrect tags, invalid URLs, etc.

      Worth it!

      Reply

    21. Seems that the code generated by xjc is not compliant with these new errors.

      Reply

      Replies

       
       
    22. This!
      I like the idea of cleaning up our JavaDocs, but I don't want to
      manually change auto-generated XJC Java files. Since I can't correctly
      fix the XJC generated Java files the whole thing feels pointless.

    23.  
    24. Also
      the wsimport tool from JDK8 generates code which is not compatible with
      this new regime. It seems the tools in JDK8 package have not been
      tested for doclint compliance.

      Reply

      Replies

       
       
    25. Yup. Event OpenJDK 8 itself disables doclint for large parts of the build :)

      http://mail.openjdk.java.net/pipermail/build-dev/2013-December/011435.html

    26.  
    27. See https://github.com/dropwizard/dropwizard/blob/master/pom.xml#L247-L255
      and https://github.com/dropwizard/dropwizard/blob/master/pom.xml#L367-L382

      for a backwards compatible way of doing this

      Reply

      Replies

       
       
    28. Saved my day!

    29. I doesn't work for jdk7, but at least it works for jdk8

    30.  
    31. Completely disable doclint is a bad advice. Javadoc doclint can be configured to enable/disable some types of checks.
      For example to disable all checks except html we can set additionalparam to
      -Xdoclint:syntax -Xdoclint:missing -Xdoclint:accessibility -Xdoclint:reference -Xdoclint:syntax
      http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html

      Reply

    32. I
      dont see any restrictions to @default tags in java8. But my build fails
      saying AnnotationProcessing issue. Are there strict rules for it too,
      (@defaultpermissions)

      Reply

    33. javadoc {
      logging.captureStandardError LogLevel.INFO
      logging.captureStandardOutput LogLevel.INFO // suppress "## warnings" message
      }

      Reply

doclint in jdk8的更多相关文章

  1. JDK7和JDK8一些重要新特性

    jdk7新特性(部分) switch支持字符串 List AutoCloseable接口实现自动关闭,在try()中 新增获取环境信息的工具方法,getJavaHomeDir,getUserHomeD ...

  2. android开发环境搭建(ubuntu15.04+jdk8+eclipse+android sdk)

    开始学习android开发,首先对其环境对搭建比较重要.平台可以选择window/linux/mac等,这里,我选择ubuntu系统,方法比较原始,当然也可以直接用google提供的android s ...

  3. win7 安装JDK7和JDK8后,卸载JDK8后出错

    这是本人学习Java过程中遇到的一些问题和解决方法,在此记录,方便本人查看,解决他人疑惑. 本人win7 x64旗舰版,同时安装了JDK7和JDK8,卸载了JDK8之后,cmd命令行输入:java - ...

  4. JDK8+Dubbo2.5.2实践

    几年前就听说过Dubbo的大名,今天由于工作需要,研究一下. 从网上找了一篇文章,非常靠谱,并且提供了简单的示例代码,基本上可以跑起来. 文章地址: http://www.cnblogs.com/Ja ...

  5. xp下安装jdk8

    下载jdk8安装包,地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载7- ...

  6. Linux Mint安装jdk8

    想到研究Java,可能学习openjdk是比较好的方式,于是去找openjdk.对于Debian based系统的安装指南是: -jdk 然而我的Linux Mint 17却无法安装.搜索之后发现如下 ...

  7. jdk8 Lambda表达式与匿名内部类比较

    Labmda表达式与匿名内部类 前言 Java Labmda表达式的一个重要用法是简化某些匿名内部类(Anonymous Classes)的写法.实际上Lambda表达式并不仅仅是匿名内部类的语法糖, ...

  8. JDK8 的 Lambda 表达式原理

    JDK8 使用一行 Lambda 表达式可以代替先前用匿名类五六行代码所做的事情,那么它是怎么实现的呢?从所周知,匿名类会在编译的时候生成与宿主类带上 $1, $2 的类文件,如写在 TestLamb ...

  9. java 28 - 7 JDK8的新特性 之 接口可以使用方法

    JDK8的新特性: http://bbs.itcast.cn/thread-24398-1-1.html 其中之一:接口可以使用方法 interface Inter { //抽象方法 public a ...

随机推荐

  1. hdu1016

    #include <stdio.h>#include <string.h> int prime[38]={0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1 ...

  2. cookie模拟

    1        为什么要使用cookie模拟          从日常项目测试过程中的问题说起. 比如要进行论坛中的文件下载功能的测试.我们都知道只有登录用户才能进行下载操作,这样我们的测试过程可能 ...

  3. 整屏滚动效果 jquery.fullPage.js插件+CSS3实现

    最近很流行整屏滚动的效果,无论是在PC端还是移动端,本人也借机学习了一下,主要通过jquery.funnPage.js插件+CSS3实现效果. 本人做的效果: PC端:http://demo.qpdi ...

  4. redis :初步使用

    redis : 1.ubuntu安装  'pip install redis-server' 2.启动    'redis-cli' 3.使用 set:  set a 1 get:  get a fl ...

  5. javascript基础(二)类型转换

    原文http://pij.robinqu.me/ 类型转换 当期望使用一个布尔值的时候,可以提供任意类型值,JavaScript将根据需要自行转换类型.类型转换可以分为隐式转换和显式转换. 显式转换 ...

  6. Spring入门学习(一)

    Spring的主要功能是控制反转和面向切面编程,下面我们就来编写第一个spring的程序来体验一下控制反转 首先是加载配置文件 <?xml version="1.0" enc ...

  7. Qt4.8.x Linux WebKit依赖库安装

    yum install "pkgconfig(gstreamer-app-0.10)"

  8. $pull

    $pull 删除所有匹配的文档,不仅仅只是删除一个. db.test.insert( {"todo":["dishes","laundry" ...

  9. WebService 调用三种方法

    //来源:http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html 最近做一个项目,由于是在别人框架里开发app,导致了很多限制 ...

  10. 酷比魔方 iwork10 旗舰版

    平板电脑自带的win10的一键恢复不是一般的慢,简直慢出个性了,历经5个小时...必须是个有耐心的人才敢一键恢复,不然强制关机就变砖了...