Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created October 28, 2025 13:29
Show Gist options
  • Select an option

  • Save ghusta/0bf6aeb516b6ac75b90b13fa53f1481d to your computer and use it in GitHub Desktop.

Select an option

Save ghusta/0bf6aeb516b6ac75b90b13fa53f1481d to your computer and use it in GitHub Desktop.
ArchUnit + JSpecify annotations
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "my.package")
public class PreferJSpecifyAnnotationsTest {
@ArchTest
static ArchRule classes_should_use_jspecify_annotations =
noClasses()
.should()
.dependOnClassesThat()
.haveFullyQualifiedName("org.springframework.lang.Nullable")
.orShould()
.dependOnClassesThat()
.haveFullyQualifiedName("org.springframework.lang.NonNull")
.because("Prefer JSpecify annotations");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment