天道酬勤,学无止境

checker-framework

NullnessChecker: how to disable only the Initialization checker?

I refer to the nullness-example in the docs (checker-framework version: 2.1.14) When I run the example as recommended to check NullnessExampleWithWarnings.java: javac -processor org.checkerframework.checker.nullness.NullnessChecker docs/examples/NullnessExampleWithWarnings.java I get the expected errors: ..\..\docs\examples\NullnessExampleWithWarnings.java:23: error: [assignment.type.incompatible] incompatible types in assignment. foo = bar; ^ found : @FBCBottom @Nullable String required: @UnknownInitialization @NonNull String ..\..\docs\examples\NullnessExampleWithWarnings.java:33: error:

2022-04-17 10:41:40    分类:问答    java   checker-framework

Checker Framework argument.type.incompatible false positive with commons-lang3

Here's my error (and yes there is an open bug on commons-lang3 jira). found : @Initialized @Nullable Console required: @Initialized @NonNull Console /Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/PebbleTemplateProcessor.java:96: error: [argument.type.incompatible] incompatible argument for parameter str of toBoolean. if ( BooleanUtils.toBoolean( line ) ) { I tried making this src/java/main/org/apache/commons/lang3/BooleanUtils.astub and I tried putting that file in src/main/resources/ package org.apache.commons.lang3; import org.checkerframework.checker.nullness

2022-03-23 13:04:13    分类:问答    java   gradle   build.gradle   gradle-kotlin-dsl   checker-framework

Checker Framework initialization.fields.uninitialize false positive

Here's my error found : @Initialized @Nullable String required: @Initialized @NonNull String /Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/Application.java:21: error: [initialization.fields.uninitialized] the constructor does not initialize fields: arg, args, dir public final class Application implements Runnable { ^ 3 errors These are initialized by picocli, so I added SuppressWarnings, not certain why it's still happening. @SuppressWarnings({ "NullAway.Init", "initialization.fields.uninitialize" }) @CommandLine.Parameters( index = "0", description = "first

2022-03-23 06:12:33    分类:问答    java   checker-framework

@Retention Java 类型检查器注解(@Retention of Java type checker annotations)

问题 Java 8 类型注释 (JSR 308) 允许类型检查器执行静态代码分析。 例如,检查器框架可以通过@NonNull注释检查可能的空@NonNull 。 各种项目定义了自己的NonNull注释,例如: org.checkerframework.checker.nullness.qual.NonNull edu.umd.cs.findbugs.annotations.NonNull javax.annotation.Nonnull javax.validation.constraints.NotNull lombok.NonNull org.eclipse.jdt.annotation.NonNull等(参见 Checker 框架手册,第 3.7 节) 对于此类注释,我希望@interface具有 @Retention(RetentionPolicy.CLASS),因为它们通常在运行时不需要。 最重要的是,代码对各自的库没有任何运行时依赖性。 虽然 org.eclipse.jdt.annotation.NonNull 遵循这种方法,但大多数其他NonNull注释,如javax.annotation.Nonnull (JSR 305) 和 org.checkerframework.checker.nullness.qual.NonNull 本身,都有 @Retention

2021-12-21 16:50:42    分类:技术分享    java   annotations   retention   checker-framework

@Retention of Java type checker annotations

The Java 8 type annotations (JSR 308) allow type checkers to perform static code analysis. For example, The Checker Framework can check for possible nullness via @NonNull annotations. Various projects define their own NonNull annotations, for example: org.checkerframework.checker.nullness.qual.NonNull edu.umd.cs.findbugs.annotations.NonNull javax.annotation.Nonnull javax.validation.constraints.NotNull lombok.NonNull org.eclipse.jdt.annotation.NonNull etc. (see The Checker Framework Manual, section 3.7) For such annotations, I would expect the @interface to have @Retention(RetentionPolicy.CLASS

2021-12-13 05:57:17    分类:问答    java   annotations   retention   checker-framework

将 Gradle 依赖项的路径传递给 Java 编译器(Passing the path to a Gradle dependency to the Java compiler)

问题 我正在使用 Checker 框架,它的注释处理器需要将“带注释的 JDK”jar 的路径传递给它,以便它可以向 JDK 类添加类型注释。 所以,我需要 Gradle 做的是获取 jar 的路径并将其传递给 java 编译器。 通常,在 Gradle 中非常简单: // tried to keep this property in the project.extensions but wouldn't work final AtomicReference jarRef = new AtomicReference() task resolveAnnotatedJdk << { def jar = configurations.compile.resolve().find { it.name == "jdk8-${checkerVersion}.jar" } logger.log LogLevel.ERROR, "Found annoated JDK at ${jar.absolutePath}" jarRef.set jar.absolutePath } 运行resolveAnnotatedJdk任务有效! 问题是试图让它在compileJava配置块中工作: compileJava { dependsOn << 'resolveAnnotatedJdk'

2021-11-09 17:16:05    分类:技术分享    java   gradle   checker-framework

Passing the path to a Gradle dependency to the Java compiler

I'm playing with the Checker Framework and its annotation processor requires the path to the "annotated JDK" jar to be passed to it so that it can add type annotations to the JDK classes. So, what I need Gradle to do is go get the path to the jar and pass it to the java compiler. Pretty simple, normally, in Gradle: // tried to keep this property in the project.extensions but wouldn't work final AtomicReference jarRef = new AtomicReference() task resolveAnnotatedJdk << { def jar = configurations.compile.resolve().find { it.name == "jdk8-${checkerVersion}.jar" } logger.log LogLevel.ERROR, "Found

2021-11-07 04:44:37    分类:问答    java   gradle   checker-framework

Java 范围构造不能使用类型使用进行注释(Java scoping construct cannot be annotated with type-use)

问题 我想用@Nullable -annotation(来自Java Checker Framework)注释一个完全限定的类名,例如: class Demo { private transient @Nullable org.apache.lucene.search.Query cached_results; // ... } 但是,这会导致错误: scoping construct cannot be annotated with type-use annotation: @checkers.nullness.quals.Nullable 如何注释完全限定的类名? 回答1 Java 语言规范(第 8 版草案)§8.3 将“UnannClassType”指定为 UnannClassType: 标识符 [TypeArguments] UnannClassOrInterfaceType 。 {Annotation} 标识符 [TypeArguments] 因此,您需要声明: private transient org.apache.lucene.search.@Nullable Query cached_results; 或者在检查器框架的增强型 java 7 编译器中: private transient org.apache.lucene.search./*@Nullable*/

2021-08-14 07:25:20    分类:技术分享    java   annotations   java-8   checker-framework

Java scoping construct cannot be annotated with type-use

I want to annotate a fully qualified class name with @Nullable-annotation (from the Java Checker Framework), e.g.: class Demo { private transient @Nullable org.apache.lucene.search.Query cached_results; // ... } However this results in the error: scoping construct cannot be annotated with type-use annotation: @checkers.nullness.quals.Nullable How can I annotate fully qualified class names?

2021-06-04 17:28:03    分类:问答    java   annotations   java-8   checker-framework