Setzen Sie findbugs NotNull als Standard für alle Klassen in einem Paket

Ich habe den folgenden einfachen Code zum Testen der FindBugs@NonNull Anmerkung mit Maven. Ich führe aus

mvn clean install

Und es schlägt fehl, weil richtig zu bauenprint(null) verletzt die Nicht-Null-Bedingung.

Sie können einstellenNonNull als Standard für alle Methodenparameter innerhalb einer Klasse unter Verwendung der Klassenanmerkung

@DefaultAnnotation(NonNull.class)

Wie kann ich einstellenNonNull als Standard für alle Methodenparameter in allen Klassen unter einem bestimmten Paket (und Unterpaketen)?

src/main/java/test/Hello.java

package test;
import edu.umd.cs.findbugs.annotations.NonNull;
public class Hello {
    static public void print(@NonNull Object value) {
        System.out.println("value: " + value.toString());
    }

    static public void main(String[] args) {
        if (args.length > 0) {
            print(args[0]);
        } else {
            print(null);
        }
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>hello</groupId>
  <artifactId>hello</artifactId>
  <version>1.0</version>

  <dependencies>
    <dependency>
      <groupId>net.sourceforge.findbugs</groupId>
      <artifactId>annotations</artifactId>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>1.3.7</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>2.5.2</version>
        <configuration>
          <includeTests>true</includeTests>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
          <execution>
            <id>findbugs-test-compile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage