Open tmtron opened 7 years ago
Latest docs propose to use -AsuppressWarnings=fbc (https://checkerframework.org/manual/#initialization-checking-suppressing-warnings). Initialization warnings are gone however null checks also doesn't seem to be reported anymore:
public class Main {
public static void main(String[] args) {
foo(null);
}
public static void foo(String a) {}
}
Without suppressing any warnings I'm getting the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project parent: Compilation failure
[ERROR] Main.java:[4,8] error: [argument.type.incompatible] incompatible argument for parameter a of foo.
[ERROR] found : null
With -AsuppressWarnings=fbc compilation just runs fine without any warnings. The other mentioned option -AsuppressWarnings=initialization. doesn't have any impact. I was using version 3.8.0.
The manual's mention of the "fbc" SuppressWarnings string is wrong. I'm sorry about that. Thank you for pointing it out; we appreciate it.
There are two relevant SuppressWarnings strings:
You did two experiments.
The behavior you are seeing seems right to me, but let us know if there is another problem.
Thank you for the clarification. However, the problem still persists. "initialization." does not suppress initialization warnings:
public class Foo {
private String a;
public Foo() {
init();
}
public void init() {
a = "gude";
}
}
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project parent: Compilation failure: Compilation failure:
[ERROR] Foo.java:[5,9] error: [initialization.fields.uninitialized] the constructor does not initialize fields: a
[ERROR] Foo.java:[6,8] error: [method.invocation.invalid] call to init() not allowed on the given receiver.
[ERROR] found : @UnderInitialization @NonNull Foo
[ERROR]
[ERROR] required: @Initialized @NonNull Foo
I am using the following configuration for the maven plugin:
<profile>
<id>checkerframework</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-proc:only</arg>
<arg>-Xmaxerrs</arg>
<arg>10000</arg>
<arg>-Xmaxwarns</arg>
<arg>10000</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-AsuppressWarnings=initialization.</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>${checkerframework.version}</version>
</path>
</annotationProcessorPaths>
<annotationProcessors>
<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<!-- Temporary until animal-sniffer-maven-plugin is released with https://github.com/mojohaus/animal-sniffer/pull/91.
Version 1.19 is broken: https://github.com/mojohaus/animal-sniffer/issues/76. -->
<animal.sniffer.skip>true</animal.sniffer.skip>
</properties>
</profile>
You are right. The behavior changed in version 3.2.0 early this year, but the documentation was not updated correctly at that time. The wrong manual is confusing to both users and developers!
To revise my previous statement, there are two relevant SuppressWarnings strings:
method.invocation.invalid
) that are issued by the framework itself. This is unfortunate, but is difficult to fix, and is what this issue is about.Thanks again for reporting this and bearing with us while we fix this documentation.
I am still puzzled. I would like to only have null checking and no initialization warnings/errors. I tried "fbc", "initialization", and "initialization." options. None of them yield the desired behavior. Am I correctly assuming that currently there is no way to suppress initialization errors but have full null validation support?
@mernst Any update on this?
@flix- Can you please take a look at the "Suppressing Warnings" section in the Initialization Checker manual and let me know if it is not clear? I think it directly answers your question, but if it is unclear or there is a bug, let us know and we will fix it. Thanks.
Encountering this issue here. Adding Checker to a large existing project which does a lot of explicit dependency injection, passing class references around in constructors to be stored for later use. So we're seeing lots of errors like:
found : @UnderInitialization(com.its.idmp.aws.AwsInstallStep.class) @NonNull AwsInstallStep
required: @Initialized @NonNull AwsInstallStep
In this case we know the code is fine. We want to turn off all of the @UnderInitialization
warnings, and only those warnings. I've tried the examples mentioned above and none of them do it. Is there something in the manual I'm missing?
I'm sorry you are having trouble. Could you please provide a concrete example of code and exactly what you did that didn't work? Otherwise it is hard to make a suggestion.
Did you try the suggestion in the "Suppressing Warnings" section of the "Initialization Checker" section of the manual? It says:
You can write
@SuppressWarnings("initialization")
on a field, constructor, or class, or pass the command-line argument-AsuppressWarnings=initialization
when running the Nullness Checker.
We need a way to suppress all initialization errors (but not the nullness checks).
Example:
The initialization checker of the checker-framework correctly reports the issues:
According to the docs of the Initialization Checker, it should be able to disable the initialization checker via a command line argument:
When we use this argument (in checker-framework 2.2.1) we still get an initialization error:
Quote from mernst in this Stackoverflow discussion "How to suppress all initialization errors" :