Skip to content

Commit 0dfb3a7

Browse files
committed
8268582: javadoc throws NPE with --ignore-source-errors option
Reviewed-by: jjg
1 parent f41e768 commit 0dfb3a7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,8 +2893,11 @@ public enum DeclarationPreviewLanguageFeatures {
28932893
}
28942894

28952895
public PreviewSummary declaredUsingPreviewAPIs(Element el) {
2896-
List<TypeElement> usedInDeclaration = new ArrayList<>();
2897-
usedInDeclaration.addAll(annotations2Classes(el));
2896+
if (el.asType().getKind() == ERROR) {
2897+
// Can happen with undocumented --ignore-source-errors option
2898+
return new PreviewSummary(Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
2899+
}
2900+
List<TypeElement> usedInDeclaration = new ArrayList<>(annotations2Classes(el));
28982901
switch (el.getKind()) {
28992902
case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE, RECORD -> {
29002903
TypeElement te = (TypeElement) el;

test/langtools/jdk/javadoc/tool/IgnoreSourceErrors.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8175219
26+
* @bug 8175219 8268582
2727
* @summary test --ignore-errors works correctly
2828
* @modules
2929
* jdk.javadoc/jdk.javadoc.internal.api
@@ -73,6 +73,12 @@ public void runIgnoreErrorsOffByDefault() throws Exception {
7373
if (!out.contains("modifier static not allowed here")) {
7474
throw new Exception("expected string not found \'modifier static not allowed here\'");
7575
}
76+
if (!out.contains("package invalid.example does not exist")) {
77+
throw new Exception("expected string not found \'package invalid.example does not exist\'");
78+
}
79+
if (!out.contains("cannot find symbol")) {
80+
throw new Exception("expected string not found \'cannot find symbol\'");
81+
}
7682
}
7783

7884
@Test
@@ -84,12 +90,19 @@ public void runIgnoreErrorsOn() throws Exception {
8490
if (!out.contains("modifier static not allowed here")) {
8591
throw new Exception("expected string not found \'modifier static not allowed here\'");
8692
}
93+
if (!out.contains("package invalid.example does not exist")) {
94+
throw new Exception("expected string not found \'package invalid.example does not exist\'");
95+
}
96+
if (!out.contains("cannot find symbol")) {
97+
throw new Exception("expected string not found \'cannot find symbol\'");
98+
}
8799
}
88100

89101
void emitSample(Path file) throws IOException {
90102
String[] contents = {
91103
"/** A java file with errors */",
92-
"public static class Foo {}"
104+
"import invalid.example.OtherClass;",
105+
"public static class Foo<T> extends OtherClass<T> {}"
93106
};
94107
Files.write(file, Arrays.asList(contents), StandardOpenOption.CREATE);
95108
}

0 commit comments

Comments
 (0)