mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
pkl-core: Migrate nullness to JSpecify (#1601)
Replace pkl-core's local nullness annotations with JSpecify annotations. Enable NullAway checking for pkl-core packages except org.pkl.core.ast and org.pkl.core.stdlib. Notable code changes: - Add a dedicated late-init constructor to VmTyped - Move VmExceptionBuilder's fallback message derivation from withCause() to build() - Split VmException rendering between builder-provided messages and string-backed messages - Initialize MessageTransport handlers with default throwing handlers - Update JSON helper collection types to allow nullable values JSON arrays and objects can contain JSON null, so the Java Map/List element types need to model nullable elements explicitly - Make public command transform APIs accept nullable transformed values Command transforms can produce null for optional/default handling, so the BiFunction and options-map element types now model that explicitly - Make ExecutorSpiException accept nullable message and cause Existing call sites can pass nullable causes from Throwable.getCause() - Remove JSR-305 semantics from `@LateInit` JSpecify does not support the same type-qualifier-nickname pattern, so `@LateInit` is now documentation plus a NullAway constructor-initialization exemption Out of scope: - NullAway checking of org.pkl.core.ast and org.pkl.core.stdlib - IntelliJ warnings related to `@LateInit` fields - Removing the JSR-305 dependency, since concurrency annotations are still in use
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import net.ltgt.gradle.errorprone.errorprone
|
||||
import net.ltgt.gradle.nullaway.nullaway
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
@@ -21,6 +23,7 @@ plugins {
|
||||
id("pklJavaLibrary")
|
||||
id("pklPublishLibrary")
|
||||
id("pklNativeLifecycle")
|
||||
id("pklJSpecify")
|
||||
idea
|
||||
}
|
||||
|
||||
@@ -57,6 +60,7 @@ dependencies {
|
||||
|
||||
add("generatorImplementation", libs.javaPoet)
|
||||
add("generatorImplementation", libs.truffleApi)
|
||||
add("generatorImplementation", libs.jspecify)
|
||||
|
||||
javaExecutableConfiguration(project(":pkl-cli", "javaExecutable"))
|
||||
}
|
||||
@@ -107,6 +111,18 @@ tasks.processResources {
|
||||
|
||||
tasks.compileJava { options.generatedSourceOutputDirectory.set(file("generated/truffle")) }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.errorprone.nullaway {
|
||||
// Do not require LateInit fields to be initialized at construction time.
|
||||
// Unfortunately, IntelliJ doesn't currently understand this,
|
||||
// and therefore emits many warnings related to LateInit.
|
||||
excludedFieldAnnotations.add("org.pkl.core.util.LateInit")
|
||||
|
||||
// For now, don't analyze code that deals with Truffle ASTs.
|
||||
unannotatedSubPackages.addAll("org.pkl.core.ast", "org.pkl.core.stdlib")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.compileKotlin { enabled = false }
|
||||
|
||||
tasks.test {
|
||||
|
||||
Reference in New Issue
Block a user