JDK-8275192 : Bogus warning generated for private fields if class implements Serializable
  • Type: Bug
  • Component: tools
  • Sub-Component: javadoc(tool)
  • Affected Version: 15,17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2021-10-12
  • Updated: 2021-10-22
  • Resolved: 2021-10-21
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
A class that implements java.io.Serializable receives warnings from javadoc if the private fields are uncommented.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run javadoc for the program below (simply "javadoc Test.java")

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No warnings
ACTUAL -
Test.java:5: warning: no comment
    private final int i = 1;

---------- BEGIN SOURCE ----------
/**
 * Comment.
 */
public class Test implements java.io.Serializable {
    private final int i = 1;
}    
---------- END SOURCE ----------

FREQUENCY : always



Comments
The behavior is intended, because even though the fields may be private, they are part of the public API for the serialized form of the class.
21-10-2021

Note that by default private instance fields of Serializable classes are part of its interface as the fields are exposed via serialization.
13-10-2021

The issue is reproducible with JDK 15. Following is my observation: JDK 8-pool - pass JDK 9 - pass JDK 14 - pass JDK 15 - fail (warning: no comment ) JDK 17 - fail (warning: no comment ) JDK 18 - fail (warning: no comment )
13-10-2021