Skip to content

Commit

Permalink
improve checkJavadocLinks.py to detect "invalid reference" (#14287)
Browse files Browse the repository at this point in the history
See background by @mkhludnev on the dev list: https://lists.apache.org/thread/pm1szr9og6qhmjzp371xwk0mvwxxkd1l

In some cases: "invalid reference" is generated, passes through Xdoclint and broken-link checkers, yet links are broken.

Instead of a 404, javadocs seems to emit this in the resulting HTML:

    <details class="invalid-tag">
    <summary>invalid reference</summary>
    <pre>flexible query parser</pre>
    </details

Fix checkJavadocLinks.py to fail the build on these.

Closes #14285
  • Loading branch information
rmuir committed Feb 25, 2025
1 parent 5969afd commit d70f436
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gradle/documentation/check-broken-links/checkJavadocLinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def __init__(self, baseURL):
self.printed = False

def handle_starttag(self, tag, attrs):
# look for explicit broken link
if tag == 'details':
for attName, attValue in attrs:
if attName == 'class' and attValue == 'invalid-tag':
raise RuntimeError('javadoc generated an invalid-tag')

# NOTE: I don't think 'a' should be in here. But try debugging
# NumericRangeQuery.html. (Could be javadocs bug, it's a generic type...)
if tag not in ('link', 'meta', 'frame', 'br', 'wbr', 'hr', 'p', 'li', 'img', 'col', 'a', 'dt', 'dd', 'input'):
Expand Down Expand Up @@ -108,7 +114,7 @@ def parse(baseURL, html):
try:
parser.feed(html)
parser.close()
except:
except Exception:
# TODO: Python's html.parser is now always lenient, which is no good for us: we want correct HTML in our javadocs
parser.printFile()
print(' WARNING: failed to parse %s:' % baseURL)
Expand Down Expand Up @@ -140,7 +146,7 @@ def checkAll(dirName):
else:
iter = os.walk(dirName)

for root, dirs, files in iter:
for root, _, files in iter:
for f in files:
main, ext = os.path.splitext(f)
ext = ext.lower()
Expand All @@ -162,7 +168,7 @@ def checkAll(dirName):
# ... then verify:
print()
print('Verify...')
for fullPath, (links, anchors) in allFiles.items():
for fullPath, (links, _) in allFiles.items():
#print fullPath
printed = False
for link in links:
Expand Down

0 comments on commit d70f436

Please sign in to comment.