8268582: javadoc throws NPE with --ignore-source-errors option

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2021-12-01 18:19:26 +00:00
parent f41e768bba
commit 0dfb3a705d
2 changed files with 21 additions and 5 deletions

View File

@ -2893,8 +2893,11 @@ public class Utils {
} }
public PreviewSummary declaredUsingPreviewAPIs(Element el) { public PreviewSummary declaredUsingPreviewAPIs(Element el) {
List<TypeElement> usedInDeclaration = new ArrayList<>(); if (el.asType().getKind() == ERROR) {
usedInDeclaration.addAll(annotations2Classes(el)); // Can happen with undocumented --ignore-source-errors option
return new PreviewSummary(Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
}
List<TypeElement> usedInDeclaration = new ArrayList<>(annotations2Classes(el));
switch (el.getKind()) { switch (el.getKind()) {
case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE, RECORD -> { case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE, RECORD -> {
TypeElement te = (TypeElement) el; TypeElement te = (TypeElement) el;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8175219 * @bug 8175219 8268582
* @summary test --ignore-errors works correctly * @summary test --ignore-errors works correctly
* @modules * @modules
* jdk.javadoc/jdk.javadoc.internal.api * jdk.javadoc/jdk.javadoc.internal.api
@ -73,6 +73,12 @@ public class IgnoreSourceErrors extends TestRunner {
if (!out.contains("modifier static not allowed here")) { if (!out.contains("modifier static not allowed here")) {
throw new Exception("expected string not found \'modifier static not allowed here\'"); throw new Exception("expected string not found \'modifier static not allowed here\'");
} }
if (!out.contains("package invalid.example does not exist")) {
throw new Exception("expected string not found \'package invalid.example does not exist\'");
}
if (!out.contains("cannot find symbol")) {
throw new Exception("expected string not found \'cannot find symbol\'");
}
} }
@Test @Test
@ -84,12 +90,19 @@ public class IgnoreSourceErrors extends TestRunner {
if (!out.contains("modifier static not allowed here")) { if (!out.contains("modifier static not allowed here")) {
throw new Exception("expected string not found \'modifier static not allowed here\'"); throw new Exception("expected string not found \'modifier static not allowed here\'");
} }
if (!out.contains("package invalid.example does not exist")) {
throw new Exception("expected string not found \'package invalid.example does not exist\'");
}
if (!out.contains("cannot find symbol")) {
throw new Exception("expected string not found \'cannot find symbol\'");
}
} }
void emitSample(Path file) throws IOException { void emitSample(Path file) throws IOException {
String[] contents = { String[] contents = {
"/** A java file with errors */", "/** A java file with errors */",
"public static class Foo {}" "import invalid.example.OtherClass;",
"public static class Foo<T> extends OtherClass<T> {}"
}; };
Files.write(file, Arrays.asList(contents), StandardOpenOption.CREATE); Files.write(file, Arrays.asList(contents), StandardOpenOption.CREATE);
} }