diff --git a/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java b/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java index 74b2b1a613..94672d51eb 100755 --- a/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java +++ b/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java @@ -33,6 +33,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -360,7 +361,7 @@ void reportInitializerError( String message, VisitorState state, Description.Builder descriptionBuilder, - List nonNullFields) { + ImmutableList nonNullFields) { // Check needed here, despite check in hasPathSuppression because initialization // checking happens at the class-level (meaning state.getPath() might not include the // method itself). diff --git a/nullaway/src/main/java/com/uber/nullaway/NullAway.java b/nullaway/src/main/java/com/uber/nullaway/NullAway.java index 65ecccd5ad..1108fb8ad1 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullAway.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullAway.java @@ -1517,12 +1517,16 @@ private void checkFieldInitialization(ClassTree tree, VisitorState state) { } } for (Element constructorElement : errorFieldsForInitializer.keySet()) { - List fieldSymbols = - errorFieldsForInitializer - .get(constructorElement) - .stream() - .map(element -> ASTHelpers.getSymbol(getTreesInstance(state).getTree(element))) - .collect(Collectors.toList()); + ImmutableList fieldSymbols = + ImmutableList.builder() + .addAll( + errorFieldsForInitializer + .get(constructorElement) + .stream() + .map( + element -> ASTHelpers.getSymbol(getTreesInstance(state).getTree(element))) + .collect(Collectors.toList())) + .build(); errorBuilder.reportInitializerError( (Symbol.MethodSymbol) constructorElement, errMsgForInitializer(errorFieldsForInitializer.get(constructorElement), state),