JDK-8161254 : javadoc erroneously treats a regular method as a property
  • Type: Bug
  • Component: tools
  • Sub-Component: javadoc(tool)
  • Affected Version: 8
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2016-07-04
  • Updated: 2018-10-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_minorUnresolved
Description
FULL PRODUCT VERSION :
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
OS X 10.11.4

A DESCRIPTION OF THE PROBLEM :
The Javadoc tool erroneously detects a regular getter method starting with "is" to be related to a property and thus generates invalid documentation.

When a class has a visible, parameter-less method that does not return void and has a name ending in "Property", this method is detected to represent a property (I think this is related to JavaFX) which is rendered specially in the API documentation.

In particular, the property name extracted from the method name (everything before the "Property" suffix) is included in the "Property Summary" of the class's documentation and the method description is replaced with "Gets the value of the property ..." instead of using the text from the Javadoc comment.

However, if a method name starts with "get" or "set" followed by a capital letter (for example "getXProperty", "getXyProperty", or "getProperty"), the method is treated as a regular method. This is so that regular getter and setter methods are not inadvertently treated in a special way, just because their name is ending with "Property". 

Unfortunately, the code handling this exception in com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap#isPropertyMethod(MethodDoc) (VisibleMemberMap.java:666 in the current development version from the Mercurial repository) does not handle the case when the method is starting with "is" and a capital letter because it is a regular getter method for a boolean.

This leads to the situation that the API documentation generated for regular boolean getter-methods with names like "isProperty" or "isAbcProperty" is invalid.

The fix for this issue is trivial. The regular expression matching getter and setter methods (VisibleMemberMap.java:665) should be extends to include getter-methods that start with "is". This means that the line

        private final Pattern pattern = Pattern.compile("[sg]et\\p{Upper}.*");

has to be replaced with

        private final Pattern pattern = Pattern.compile("([sg]et|is)\\p{Upper}.*");

This should be sufficient for fixing the problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Save the Java cod from the test case as "TestCase.java".
2) Run "javadoc TestCase.java".
3) Open "TestCase.html" in a browser. The generated documentation is invalid.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The generated documentation for the TestCase class (TestCase.html) should not have a "Property Summary" section.

The documentation of the method "isAbcProperty" should look like:

    isAbcProperty

    public boolean isAbcProperty()

    Returns the value of "abcProperty".

    Returns:
        value of "abcProperty".

The documentation of "isProperty" should look like:

    isProperty

    public boolean isProperty()

    Returns the value of "property".

    Returns:
        value of "property".

ACTUAL -
The generated documentatiohn for the TestCase class (TestCase.html) has a "Property Summary" section with the following content:

Type 	Property and Description
boolean 	isAbc
Gets the value of the property abcProperty.
boolean 	is
Gets the value of the property property.

The documentation of the "isAbcProperty" method looks like:

    isAbcProperty

    public boolean isAbcProperty()

    Gets the value of the property abcProperty.

The documentation of the "isProperty" methods looks like:

    isProperty

    public boolean isProperty()

    Gets the value of the property property.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/**
 * Test case for demonstrating the bug.
 */
public class TestCase {

    /**
     * Returns the value of "abcProperty".
     * 
     * @return value of "abcProperty".
     */
    public boolean isAbcProperty() {
        return false;
    }
    
    /**
     * Returns the value of "property".
     * 
     * @return value of "property".
     */
    public boolean isProperty() {
        return false;
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
A possible workaround is to use the "get" prefix for boolean getter methods instead of using the "is" prefix. However, this might violate some style guidelines.


Comments
Test Result == 7u101 - Pass 8u92 - Fail 9 ea b-126 - Pass ==
25-07-2016

We should check whether the issue occurs with or without the -javafx option. We should check whether the issue still occurs with the old doclet in 9.
13-07-2016

This issue is only observed on 8u92 and not on 9 ea b-126 Result on 8u92 == isAbcProperty public boolean isAbcProperty() Gets the value of the property abcProperty. isProperty public boolean isProperty() Gets the value of the property property. == Result on 9 ea b-126 == isAbcProperty public boolean isAbcProperty() Returns the value of "abcProperty". Returns: value of "abcProperty". isProperty public boolean isProperty() Returns the value of "property". Returns: value of "property". ==
13-07-2016