error-prone icon indicating copy to clipboard operation
error-prone copied to clipboard

Var: False positves

Open xenoterracide opened this issue 3 years ago • 3 comments

I don't see anything that would suggest any of these should be resolved to mutable.

package com.xenoterracide.ppm.transactional.dataloaders;

import com.netflix.graphql.dgs.DgsDataLoader;
import com.xenoterracide.ppm.transactional.domainmodel.repositories.ExceptionRepository;
import com.xenoterracide.ppm.transactional.types.Exception;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import org.dataloader.BatchLoader;

@DgsDataLoader
public class ExceptionDataLoader implements BatchLoader<Long, Exception> {

  private final ExceptionRepository repository;

  ExceptionDataLoader(ExceptionRepository repository) {
    this.repository = repository;
  }

  @Override
  public CompletionStage<List<Exception>> load( List<Long> keys) {
    return CompletableFuture.supplyAsync(() -> {
      return this.repository.findAllById(keys).map(e -> {
        return Exception.newBuilder().id(String.valueOf(e.getId())).build();
      }).collect(Collectors.toList());
    });
  }
}
          ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean '@Var var entity = new ExceptionEntity();'?
/Users/nqy642/IdeaProjects/iw-pm-backend/module/controller/transactional/src/main/java/com/xenoterracide/ppm/transactional/dataloaders/ExceptionDataLoader.java:23: error: [Var] Non-constant variable missing @Var annotation
  ExceptionDataLoader(ExceptionRepository repository) {
                                          ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'ExceptionDataLoader(@Var ExceptionRepository repository) {'?
/Users/nqy642/IdeaProjects/iw-pm-backend/module/controller/transactional/src/main/java/com/xenoterracide/ppm/transactional/dataloaders/ExceptionDataLoader.java:28: error: [Var] Non-constant variable missing @Var annotation
  public CompletionStage<List<Exception>> load(List<Long> keys) {
                                                          ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'public CompletionStage<List<Exception>> load(@Var List<Long> keys) {'?
/Users/nqy642/IdeaProjects/iw-pm-backend/module/controller/transactional/src/main/java/com/xenoterracide/ppm/transactional/dataloaders/ExceptionDataLoader.java:30: error: [Var] Non-constant variable missing @Var annotation
      return this.repository.findAllById(keys).map(e -> {
                                                   ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean 'return this.repository.findAllById(keys).map(@Var e -> {'?
16 errors
2 warnings

xenoterracide avatar Aug 25 '22 19:08 xenoterracide

What version of Error Prone are you using?

rickie avatar Aug 30 '22 12:08 rickie

sorry that I forgot that

com.google.errorprone:error_prone_annotation:2.15.0
com.google.errorprone:error_prone_check_api:2.15.0
com.google.errorprone:error_prone_core:2.15.0
com.google.errorprone:error_prone_type_annotations:2.15.0
com.uber.nullaway:nullaway:0.9.9

I wonder if this causes a problem since I use java17

com.google.errorprone:javac:9+181-r4173-1=errorProneJavac

xenoterracide avatar Aug 30 '22 12:08 xenoterracide

com.google.errorprone:javac:9+181-r4173-1=errorProneJavac will only be used with JDK 8 in the Gradle plugin.

tbroyer avatar Aug 30 '22 13:08 tbroyer