Make codegen default to jspecify NonNull annotations (#1607)

With JSpecify now a dependency of pkl-config-java, this moves the
non-null annotation to jspecify's.
This makes it simpler for users to do nullness checks, as tooling
already understands JSpecify nullness annotations.
This commit is contained in:
Daniel Chao
2026-05-21 21:12:15 -07:00
committed by GitHub
parent 8e2e5e4ba8
commit da4dd4c4f8
9 changed files with 22 additions and 10 deletions
+1 -1
View File
@@ -198,7 +198,7 @@ For Spring Boot applications, and for users of `pkl-config-java` compiling the g
.--non-null-annotation
[%collapsible]
====
Default: `org.pkl.config.java.mapper.NonNull` +
Default: `org.jspecify.annotations.NonNull` +
Fully qualified name of the annotation type to use for annotating non-null types. +
The specified annotation type must be annotated with `@java.lang.annotation.Target(ElementType.TYPE_USE)`
or the generated code may not compile.
+1 -1
View File
@@ -423,7 +423,7 @@ For Spring Boot applications, and for users of `pkl-config-java` compiling the g
.nonNullAnnotation: Property<String>
[%collapsible]
====
Default: `"org.pkl.config.java.mapper.NonNull"` +
Default: `"org.jspecify.annotations.NonNull"` +
Example: `nonNullAnnotation = "org.project.MyAnnotation"` +
Fully qualified name of the annotation type to use for annotating non-null types. +
The specified annotation type must be annotated with `@java.lang.annotation.Target(ElementType.TYPE_USE)`
@@ -37,6 +37,10 @@ The following APIs have been removed without replacement.
* `org.pkl.config.java.Config#makeConfig` (pr:https://github.com/apple/pkl/pull/1531[])
The following APIs have been deprecated for removal.
* `org.pkl.config.java.mapper.NonNull` (https://github.com/apple/pkl/pull/1607[#1607]).
.XXX
[%collapsible]
====
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "CanConvertToMultiDollarString")
package org.pkl.codegen.java
@@ -172,7 +172,7 @@ class JavaCodeGenerator(
val annotation = codegenOptions.nonNullAnnotation
val className =
if (annotation == null) {
ClassName.get("org.pkl.config.java.mapper", "NonNull")
ClassName.get("org.jspecify.annotations", "NonNull")
} else {
toClassName(annotation)
}
@@ -5,8 +5,8 @@ import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.pkl.config.java.mapper.Named;
import org.pkl.config.java.mapper.NonNull;
import org.pkl.core.DataSize;
import org.pkl.core.Duration;
@@ -5,8 +5,8 @@ import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.pkl.config.java.mapper.Named;
import org.pkl.config.java.mapper.NonNull;
import org.pkl.core.Duration;
public final class Mod {
@@ -5,8 +5,8 @@ import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.pkl.config.java.mapper.Named;
import org.pkl.config.java.mapper.NonNull;
/**
* module comment.
@@ -11,8 +11,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import org.jspecify.annotations.NonNull;
import org.pkl.config.java.mapper.Named;
import org.pkl.config.java.mapper.NonNull;
import org.pkl.core.DataSize;
import org.pkl.core.DataSizeUnit;
import org.pkl.core.Duration;
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,16 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** Indicates that a type does not accept {@code null} as a value. */
/**
* Indicates that a type does not accept {@code null} as a value.
*
* <p>This annotation is deprecated, and any usage should be replaced with {@link
* org.jspecify.annotations.NonNull}.
*
* @deprecated since 0.32.0
*/
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.CLASS)
@Documented
@Deprecated(forRemoval = true)
public @interface NonNull {}