118
118
import static com .sun .source .doctree .DocTree .Kind .LINK ;
119
119
import static com .sun .source .doctree .DocTree .Kind .LINK_PLAIN ;
120
120
import static com .sun .source .doctree .DocTree .Kind .SEE ;
121
+ import static com .sun .source .doctree .DocTree .Kind .START_ELEMENT ;
121
122
import static com .sun .source .doctree .DocTree .Kind .TEXT ;
122
123
import static jdk .javadoc .internal .doclets .toolkit .util .CommentHelper .SPACER ;
123
124
@@ -1273,21 +1274,37 @@ private void addCommentTags(Element element, List<? extends DocTree> tags, boole
1273
1274
}
1274
1275
}
1275
1276
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 ) {
1277
1287
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 ();
1284
1293
}
1285
1294
1286
1295
if (name != null ) {
1287
1296
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
+ }
1291
1308
}
1292
1309
}
1293
1310
return false ;
@@ -1377,6 +1394,7 @@ public ContentBuilder add(CharSequence text) {
1377
1394
// Array of all possible inline tags for this javadoc run
1378
1395
configuration .tagletManager .checkTags (element , trees , true );
1379
1396
commentRemoved = false ;
1397
+ List <Name > openTags = new ArrayList <>();
1380
1398
1381
1399
for (ListIterator <? extends DocTree > iterator = trees .listIterator (); iterator .hasNext ();) {
1382
1400
boolean isFirstNode = !iterator .hasPrevious ();
@@ -1385,14 +1403,16 @@ public ContentBuilder add(CharSequence text) {
1385
1403
1386
1404
if (context .isFirstSentence ) {
1387
1405
// Ignore block tags
1388
- if (ignoreNonInlineTag (tag ))
1406
+ if (ignoreNonInlineTag (tag , openTags )) {
1389
1407
continue ;
1408
+ }
1390
1409
1391
1410
// Ignore any trailing whitespace OR whitespace after removed html comment
1392
1411
if ((isLastNode || commentRemoved )
1393
1412
&& tag .getKind () == TEXT
1394
- && isAllWhiteSpace (ch .getText (tag )))
1413
+ && isAllWhiteSpace (ch .getText (tag ))) {
1395
1414
continue ;
1415
+ }
1396
1416
1397
1417
// Ignore any leading html comments
1398
1418
if ((isFirstNode || commentRemoved ) && tag .getKind () == COMMENT ) {
@@ -1638,6 +1658,10 @@ protected Boolean defaultAction(DocTree node, Content c) {
1638
1658
if (allDone )
1639
1659
break ;
1640
1660
}
1661
+ // Close any open inline tags
1662
+ while (!openTags .isEmpty ()) {
1663
+ result .add (RawHtml .endElement (removeLastHelper (openTags )));
1664
+ }
1641
1665
return result ;
1642
1666
}
1643
1667
0 commit comments