Skip to content

Commit

Permalink
8268582: javadoc throws NPE with --ignore-source-errors option
Browse files Browse the repository at this point in the history
Backport-of: 0dfb3a705d2ad0ce4ac0f7dd18fb65d7ae735f16
  • Loading branch information
Alexey Pavlyutkin authored and Yuri Nesterenko committed May 23, 2023
1 parent 39a6b55 commit 17b3640
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Expand Up @@ -2936,8 +2936,11 @@ public enum DeclarationPreviewLanguageFeatures {
}

public PreviewSummary declaredUsingPreviewAPIs(Element el) {
List<TypeElement> usedInDeclaration = new ArrayList<>();
usedInDeclaration.addAll(annotations2Classes(el));
if (el.asType().getKind() == ERROR) {
// 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()) {
case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE, RECORD -> {
TypeElement te = (TypeElement) el;
Expand Down
19 changes: 16 additions & 3 deletions test/langtools/jdk/javadoc/tool/IgnoreSourceErrors.java
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 8175219
* @bug 8175219 8268582
* @summary test --ignore-errors works correctly
* @modules
* jdk.javadoc/jdk.javadoc.internal.api
Expand Down Expand Up @@ -73,6 +73,12 @@ public void runIgnoreErrorsOffByDefault() throws Exception {
if (!out.contains("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
Expand All @@ -84,12 +90,19 @@ public void runIgnoreErrorsOn() throws Exception {
if (!out.contains("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 {
String[] contents = {
"/** 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);
}
Expand Down

1 comment on commit 17b3640

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.