Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8347048

Error generated when running javadoc with --allow-script-in-comments option

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • 21, 22, 23, 24
    • tools
    • None
    • Tested on Mac M1, running with 15.1.1 (24B91) with OpenJDK 21, 22, 23 and EA builds for OpenJDK 24.

      I tested the command `javadoc --allow-script-in-comments -d ./docs User.java` on the attached sample file. The output shows errors:

      ```
      Loading source file User.java...
      Constructing Javadoc information...
      Building index for all the packages and classes...
      Standard Doclet version 24-ea+27-3551
      Building tree for all the packages and classes...
      Generating ./docs/User.html...
      User.java:15: error: malformed HTML
               * if (monthDiff < 0 ||
                                   ^
      User.java:16: error: bad HTML entity
               * (monthDiff === 0 && today.getDate() > birthDate.getDate())) {
                                            ^
      User.java:16: error: bad HTML entity
               * (monthDiff === 0 && today.getDate() > birthDate.getDate())) {
                                             ^
      ```

      This translates into malformed HTML output like:

      ```
      <div class="block">The method calculates a driver's age and checks if they meet
       the minimum age requirement.

       <script>
         function isEligible(birthDateString) {
           const birthDate = new Date(birthDateString);
           const today = new Date();
           const age = today.getFullYear() - birthDate.getFullYear();
           const monthDiff = today.getMonth() - birthDate.getMonth();
           if (monthDiff <span class="invalid-tag">invalid input: '&lt;'</span> 0 ||
                 (monthDiff === 0 <span class="invalid-tag">invalid input: '&amp;'</span><span class="invalid-tag">invalid input: '&amp;'</span> today.getDate() &gt; birthDate.getDate())) {
             return age - 1;
           }
           return age;
         }
         console.log(isEligible("1990-04-15"))
       </script></div>
      </section>
      ```

      I tried the same with OpenJDK 21, 22, 23 and got the same results.

            hannesw Hannes Wallnoefer
            amihalceanu Ana-Maria Mihalceanu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: