diff --git a/dependencies/java/kotlin-annotations/kotlin-annotations-jvm-1.3.72.jar b/dependencies/java/kotlin-annotations/kotlin-annotations-jvm-1.3.72.jar new file mode 100644 index 000000000..54bd50782 Binary files /dev/null and b/dependencies/java/kotlin-annotations/kotlin-annotations-jvm-1.3.72.jar differ diff --git a/infer/annotations/Makefile b/infer/annotations/Makefile index d4a292142..149204880 100644 --- a/infer/annotations/Makefile +++ b/infer/annotations/Makefile @@ -8,6 +8,7 @@ include $(ROOT_DIR)/Makefile.config CWD = $(shell pwd) JSR_JAR = $(DEPENDENCIES_DIR)/java/jsr-305/jsr305.jar +KOTLIN_ANNOT_JAR = $(DEPENDENCIES_DIR)/java/kotlin-annotations/kotlin-annotations-jvm-1.3.72.jar SOURCES_DIR = src/main/java ANNOT_SOURCES = $(shell find $(SOURCES_DIR)/com/facebook/infer/annotation -name "*.java") ANNOT_CLASSES = 'annot_classes' @@ -19,7 +20,7 @@ all: $(ANNOTATIONS_JAR) $(SOURCES_JAR) $(ANNOTATIONS_JAR): $(ANNOT_SOURCES) $(MKDIR_P) $(ANNOT_CLASSES) - $(JAVAC) -source 7 -target 7 -cp $(JSR_JAR) $(ANNOT_SOURCES) -d $(ANNOT_CLASSES) + $(JAVAC) -source 7 -target 7 -cp $(JSR_JAR):$(KOTLIN_ANNOT_JAR) $(ANNOT_SOURCES) -d $(ANNOT_CLASSES) cd $(ANNOT_CLASSES) && jar cvf $(ANNOTATIONS_JAR) com $(SOURCES_JAR): $(ANNOT_SOURCES) diff --git a/infer/annotations/pom.xml b/infer/annotations/pom.xml index 8db5f97c8..732fcc88c 100644 --- a/infer/annotations/pom.xml +++ b/infer/annotations/pom.xml @@ -65,6 +65,12 @@ jsr305 3.0.1 + + + org.jetbrains.kotlin + kotlin-annotations-jvm + 1.3.72 + diff --git a/infer/annotations/src/main/java/com/facebook/infer/annotation/Nullsafe.java b/infer/annotations/src/main/java/com/facebook/infer/annotation/Nullsafe.java index 8602a932c..dce0dacc1 100644 --- a/infer/annotations/src/main/java/com/facebook/infer/annotation/Nullsafe.java +++ b/infer/annotations/src/main/java/com/facebook/infer/annotation/Nullsafe.java @@ -11,9 +11,22 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; +import kotlin.annotations.jvm.MigrationStatus; +import kotlin.annotations.jvm.UnderMigration; @Retention(RetentionPolicy.CLASS) @Target({ElementType.TYPE}) +// These 2 annotations are needed for better interop of @Nullsafe with Kotlin, +// essentially telling it that both params and return values are non-null by +// default. +@Nonnull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) +// This annotation is needed for kotlinc to recognize {@code +// TypeQualifierDefault} without explicitly passing -Xjsr305=strict flag (which +// may be problematic in large codebases). +@UnderMigration(status = MigrationStatus.STRICT) /** * Configures nullability checking mode of annotated classes; a more general version of {@link * NullsafeStrict}.