uber / uber/NullAway

Better documentation and tests for initializer support

Open
#482 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.1k
Forks
370
Avg merge
1d 13h
Merged PRs (30d)
68

Description

not sure how to fix this

> Task :cli:config:compileJava FAILED
/home/xeno/IdeaProjects/brix/modules/cli/config/src/main/java/com/xenoterracide/cli/config/CliCommand.java:32: error: [NullAway] initializer method does not guarantee @NonNull fields language (line 22), moduleType (line 24), project (line 26) are initialized along all control-flow paths (remember to check for exceptions or early returns).
  CliCommand( Dispatcher dispatcher ) {
  ^
    (see http://t.uber.com/nullaway )
1 error

I've tried adding this via the ep plugin

    option("NullAway:AnnotatedPackages", "com.xenoterracide")
    option("NullAway:ExternalInitAnnotations", "picocli.CommandLine.Option")
    option("NullAway:CustomInitializerAnnotations", "picocli.CommandLine.Option")
package com.xenoterracide.cli.config;

import com.xenoterracide.brix.cli.api.CliConfiguration;
import com.xenoterracide.brix.dispatch.Dispatcher;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.springframework.stereotype.Component;
import picocli.CommandLine;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

@Component
public class CliCommand implements CliConfiguration, Runnable {

  private final Dispatcher dispatcher;

  private Path workdir = Paths.get( "" );

  private String language;

  private String moduleType;

  private String project;

  private @MonotonicNonNull String name;

  private @MonotonicNonNull Path repo;

  CliCommand( Dispatcher dispatcher ) {
    this.dispatcher = dispatcher;
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString( this, ToStringStyle.MULTI_LINE_STYLE );
  }

  @Override
  public Optional<Path> getRepo() {
    return Optional.ofNullable( repo );
  }

  @CommandLine.Option(
    names = {"--repo"},
    description = "Repository path from the current working directory. " +
      "Templates and configs are looked up relative to here. If the config " +
      "isn't found here, then we will search ~/.config/brix"
  )
  public void setRepo( Path repo ) {
    this.repo = repo;
  }

  @Override
  public Path getWorkdir() {
    return workdir;
  }

  @CommandLine.Option(
    names = {"--workdir"},
    defaultValue = "",
    showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
    description = "The working directory you want your destination paths to be relative to." +
      " Defaults to current working directory"
  )
  public void setWorkdir( Path workdir ) {
    this.workdir = workdir;
  }

  @Override
  public String getProject() {
    return project;
  }

  @CommandLine.Parameters(
    index = "2",
    description = "The name of the project you're generating code for."
  )
  public void setProject( String project ) {
    this.project = project;
  }

  @Override
  public String getLanguage() {
    return language;
  }

  @Override
  public String getModuleType() {
    return moduleType;
  }

  @CommandLine.Parameters(
    index = "1",
    description = "The type of code you're generating e.g controller, also the name of the config" +
      " file without the extension."
  )
  public void setModuleType( String moduleType ) {
    this.moduleType = moduleType;
  }

  @Override
  public @MonotonicNonNull String getName() {
    return name;
  }

  @CommandLine.Parameters(
    index = "3",
    description = "The name of the module to be created within the project.",
    arity = "0"
  )
  public void setName( String name ) {
    this.name = name;
  }

  @CommandLine.Parameters(
    index = "0",
    description = "The programming language you're generating code for. Directory under --dir"
  )
  public void setLanguage( String language ) {
    this.language = language;
  }

  @Override
  public void run() {
    dispatcher.run();
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the NullAway failure at CliCommand.java:32 and the attempted initializer options for picocli.CommandLine.Option. Review how initializer support is configured and determine which documentation and tests should cover the shown CliCommand constructor and parameter setters. Done means the supported configuration is documented and the relevant test coverage demonstrates that the NullAway error is handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, documentation, testing-qa
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.