118118import static com .sun .source .doctree .DocTree .Kind .LINK ;
119119import static com .sun .source .doctree .DocTree .Kind .LINK_PLAIN ;
120120import static com .sun .source .doctree .DocTree .Kind .SEE ;
121+ import static com .sun .source .doctree .DocTree .Kind .START_ELEMENT ;
121122import static com .sun .source .doctree .DocTree .Kind .TEXT ;
122123import static jdk .javadoc .internal .doclets .toolkit .util .CommentHelper .SPACER ;
123124
@@ -1273,21 +1274,37 @@ private void addCommentTags(Element element, List<? extends DocTree> tags, boole
12731274 }
12741275 }
12751276
1276- boolean ignoreNonInlineTag (DocTree dtree ) {
1277+ // helper methods because jdk21 functionality is not allowed
1278+ private static Name getLastHelper (List <Name > l ) {
1279+ return l .get (l .size () - 1 );
1280+ }
1281+
1282+ private static Name removeLastHelper (List <Name > l ) {
1283+ return l .remove (l .size () - 1 );
1284+ }
1285+
1286+ boolean ignoreNonInlineTag (DocTree dtree , List <Name > openTags ) {
12771287 Name name = null ;
1278- if (dtree .getKind () == Kind .START_ELEMENT ) {
1279- StartElementTree setree = (StartElementTree )dtree ;
1280- name = setree .getName ();
1281- } else if (dtree .getKind () == Kind .END_ELEMENT ) {
1282- EndElementTree eetree = (EndElementTree )dtree ;
1283- name = eetree .getName ();
1288+ Kind kind = dtree .getKind ();
1289+ if (kind == Kind .START_ELEMENT ) {
1290+ name = ((StartElementTree )dtree ).getName ();
1291+ } else if (kind == Kind .END_ELEMENT ) {
1292+ name = ((EndElementTree )dtree ).getName ();
12841293 }
12851294
12861295 if (name != null ) {
12871296 HtmlTag htmlTag = HtmlTag .get (name );
1288- if (htmlTag != null &&
1289- htmlTag .blockType != jdk .javadoc .internal .doclint .HtmlTag .BlockType .INLINE ) {
1290- return true ;
1297+ if (htmlTag != null ) {
1298+ if (htmlTag .blockType != HtmlTag .BlockType .INLINE ) {
1299+ return true ;
1300+ }
1301+ // Keep track of open inline tags that need to be closed, see 8326332
1302+ if (kind == START_ELEMENT && htmlTag .endKind == HtmlTag .EndKind .REQUIRED ) {
1303+ openTags .add (name );
1304+ } else if (kind == Kind .END_ELEMENT && !openTags .isEmpty ()
1305+ && getLastHelper (openTags ).equals (name )) {
1306+ removeLastHelper (openTags );
1307+ }
12911308 }
12921309 }
12931310 return false ;
@@ -1377,6 +1394,7 @@ public ContentBuilder add(CharSequence text) {
13771394 // Array of all possible inline tags for this javadoc run
13781395 configuration .tagletManager .checkTags (element , trees , true );
13791396 commentRemoved = false ;
1397+ List <Name > openTags = new ArrayList <>();
13801398
13811399 for (ListIterator <? extends DocTree > iterator = trees .listIterator (); iterator .hasNext ();) {
13821400 boolean isFirstNode = !iterator .hasPrevious ();
@@ -1385,14 +1403,16 @@ public ContentBuilder add(CharSequence text) {
13851403
13861404 if (context .isFirstSentence ) {
13871405 // Ignore block tags
1388- if (ignoreNonInlineTag (tag ))
1406+ if (ignoreNonInlineTag (tag , openTags )) {
13891407 continue ;
1408+ }
13901409
13911410 // Ignore any trailing whitespace OR whitespace after removed html comment
13921411 if ((isLastNode || commentRemoved )
13931412 && tag .getKind () == TEXT
1394- && isAllWhiteSpace (ch .getText (tag )))
1413+ && isAllWhiteSpace (ch .getText (tag ))) {
13951414 continue ;
1415+ }
13961416
13971417 // Ignore any leading html comments
13981418 if ((isFirstNode || commentRemoved ) && tag .getKind () == COMMENT ) {
@@ -1638,6 +1658,10 @@ protected Boolean defaultAction(DocTree node, Content c) {
16381658 if (allDone )
16391659 break ;
16401660 }
1661+ // Close any open inline tags
1662+ while (!openTags .isEmpty ()) {
1663+ result .add (RawHtml .endElement (removeLastHelper (openTags )));
1664+ }
16411665 return result ;
16421666 }
16431667
0 commit comments