1
1
/*
2
- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -220,20 +220,14 @@ private void reportMissingFile(Path file) {
220
220
221
221
@ Override
222
222
public boolean isOK () {
223
- return duplicateIds == 0
224
- && missingIds == 0
225
- && missingFiles == 0
226
- && badSchemes == 0 ;
223
+ return log .noErrors () && (missingFiles == 0 );
227
224
}
228
225
229
226
@ Override
230
227
public void close () {
231
- report ();
232
- if (!isOK ()) {
233
- throw new RuntimeException (
234
- "LinkChecker encountered errors. Duplicate IDs: "
235
- + duplicateIds + ", Missing IDs: " + missingIds
236
- + ", Missing Files: " + missingFiles + ", Bad Schemes: " + badSchemes );
228
+ if (!log .noErrors ()) {
229
+ report ();
230
+ throw new RuntimeException ("LinkChecker encountered errors; see log above." );
237
231
}
238
232
}
239
233
@@ -276,6 +270,11 @@ private void foundReference(int line, String ref) {
276
270
p = currFile .getParent ().resolve (resolvedUriPath ).normalize ();
277
271
}
278
272
273
+ if (!Files .exists (p )) {
274
+ log .log (currFile , line , "missing file reference: " + log .relativize (p ));
275
+ return ;
276
+ }
277
+
279
278
if (fragment != null && !fragment .isEmpty ()) {
280
279
foundReference (line , p , fragment );
281
280
}
@@ -392,7 +391,7 @@ class IDTable {
392
391
393
392
void addID (int line , String name ) {
394
393
if (checked ) {
395
- throw new IllegalStateException ("Adding ID after file has been" );
394
+ throw new IllegalStateException ("Adding ID after file has been checked " );
396
395
}
397
396
Objects .requireNonNull (name );
398
397
IDInfo info = map .computeIfAbsent (name , _ -> new IDInfo ());
@@ -413,7 +412,9 @@ void addReference(String name, Path from, int line) {
413
412
if (name != null ) {
414
413
IDInfo id = map .get (name );
415
414
if (id == null || !id .declared ) {
416
- log .log (log .relativize (from ), line , "id not found: " + this .pathOrURI + "#" + name );
415
+ log .log (log .relativize (from ), line ,
416
+ "id not found: " + this .pathOrURI + "#" + name );
417
+ LinkChecker .this .missingIds ++;
417
418
}
418
419
}
419
420
} else {
@@ -429,7 +430,8 @@ void check() {
429
430
map .forEach ((name , id ) -> {
430
431
if (name != null && !id .declared ) {
431
432
for (Position ref : id .references ) {
432
- log .log (log .relativize (ref .path ), ref .line , "id not found: " + this .pathOrURI + "#" + name );
433
+ log .log (log .relativize (ref .path ), ref .line ,
434
+ "id not found: " + this .pathOrURI + "#" + name );
433
435
}
434
436
missingIds ++;
435
437
}
0 commit comments