Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ImmutablesBuilderMissingInitialization on Java 15 when immutables isn't on the classpath #1507

Merged
merged 3 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.immutables.value.Generated;

/**
* Checks that all required fields in an immutables.org generated builder have been populated.
Expand Down Expand Up @@ -307,9 +306,15 @@ private <I, O extends I> Function<I, Optional<O>> filterByType(Class<O> clazz) {
*/
private static boolean extendsImmutablesGeneratedClass(Type type, VisitorState state) {
if (type.tsym instanceof ClassSymbol) {
return Optional.ofNullable(type.tsym.getAnnotation(Generated.class))
.map(generated -> generated.generator().equals("Immutables"))
.orElseGet(() -> extendsImmutablesGeneratedClass(((ClassSymbol) type.tsym).getSuperclass(), state));
return type.tsym.getRawAttributes().stream()
.filter(compound -> compound.type
.tsym
.getQualifiedName()
.contentEquals("org.immutables.value.Generated"))
.map(annotation -> annotation.member(state.getName("generator")))
.filter(Objects::nonNull)
.anyMatch(attribute -> Objects.equals(attribute.getValue(), "Immutables"))
|| extendsImmutablesGeneratedClass(((ClassSymbol) type.tsym).getSuperclass(), state);
}
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1507.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Fix ImmutablesBuilderMissingInitialization in java15
links:
- https://github.com/palantir/gradle-baseline/pull/1507