Skip to content

Commit

Permalink
Exclude null-checking on fields with injectors such as FXML (#74)
Browse files Browse the repository at this point in the history
Fixes #66
  • Loading branch information
jskov authored Jun 23, 2024
1 parent 6720ca2 commit 3e061fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ Note that this is a plugin to ErrorProne, so is also affected by errorprone conf
Comma-separated list of packages to be scanned (will include sub-packages)
* `dk.mada.style.null-checker.exclude-packages = `
Comma-separated list of packages to be excluded from scanning
* `dk.mada.style.null-checker.exclude-field-annotations = javafx.fxml.FXML`
Comma-separated list of classes that are assumed to inject (non-null) value into fields


**Sonar**

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/dk/mada/style/config/PluginConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public record FormatterConfiguration(boolean enabled, String include, String exc
/**
* Null-checker configuration.
*
* @param enabled flag to activate null-checker
* @param includePackages a comma-separated list of packages to scan
* @param excludePackages a comma-separated list of packages to ignore
* @param enabled flag to activate null-checker
* @param includePackages a comma-separated list of packages to scan (restricted regexp syntax)
* @param excludePackages a comma-separated list of packages to ignore (restricted regexp syntax)
* @param excludedFieldAnnotations a comma-seaparated list of classes to ignore (restricted regexp syntax)
*/
public record NullcheckerConfiguration(boolean enabled, String includePackages, String excludePackages) {
public record NullcheckerConfiguration(boolean enabled, String includePackages, String excludePackages,
String excludedFieldAnnotations) {
}

/**
Expand Down Expand Up @@ -132,7 +134,8 @@ public PluginConfiguration(Project project) {
nullcheckerConf = new NullcheckerConfiguration(
getBoolProperty("null-checker.enabled", true),
getProperty("null-checker.include-packages", "dk"),
getProperty("null-checker.exclude-packages", ""));
getProperty("null-checker.exclude-packages", ""),
getProperty("null-checker.exclude-field-annotations", ""));

sonarConf = new SonarConfiguration(
getBoolProperty("sonar.enabled", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void configureErrorProne(ErrorProneOptions er) {
er.check("NullAway", CheckSeverity.ERROR);
er.option("NullAway:AnnotatedPackages", makeValidNoSpaceString(nullcheckerConfig.includePackages()));
er.option("NullAway:UnannotatedSubPackages", makeValidNoSpaceString(nullcheckerConfig.excludePackages()));
er.option("NullAway:ExcludedFieldAnnotations", makeValidNoSpaceString(nullcheckerConfig.excludedFieldAnnotations()));
}
}

Expand Down

0 comments on commit 3e061fc

Please sign in to comment.