Can't get annotated JDK to work

535 views
Skip to first unread message

pio...@gmail.com

unread,
Sep 17, 2016, 8:00:47 PM9/17/16
to Checker Framework Developers
Hi, I have a problem setting up Checker framework in my project. I'm using IntelliJ Idea and Maven. I've done everything like the installation instruction says, but when I compile the project, I'm getting a following warning:
Warning:java: You do not seem to be using the distributed annotated JDK. To fix the problem, supply this argument (first, fill in the "...") when you run javac: -Xbootclasspath/p:.../checker/dist/jdk8.jar.
The problem probably lies in properties section of pom.xml, because IntelliJ marks the <annotatedJdk> part as error ("Cannot resolve symbol org.checkerframework:jdk8:jar"). I can't find any similar question anywhere, and I'll be grateful for any help. Below is complete pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>chess</groupId>
    <artifactId>chess</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Chess</name>
    <description>Chess interface</description>

    <properties>
        <!-- These properties will be set by the Maven Dependency plugin -->
        <!-- Change to jdk7 if using Java 7 -->
        <annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
        <!-- Uncomment to use the type annotations compiler. -->
        <!-- <typeAnnotationsJavac>${org.checkerframework:compiler:jar}</typeAnnotationsJavac> -->
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.8</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>2.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- The type annotations compiler - uncomment if desired -->
        <!-- <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>compiler</artifactId>
            <version>2.1.3</version>
        </dependency> -->
        <!-- The annotated JDK to use (change to jdk7 if using Java 7) -->
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>jdk8</artifactId>
            <version>2.1.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- This plugin will set properties values using dependency information -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                    <annotationProcessors>
                        <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>

                        <!-- Add all the checkers you want to enable here -->
                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                    </annotationProcessors>
                    <compilerArgs>
                        <!-- location of the annotated JDK, which comes from a Maven dependency -->
                        <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
                        <!-- Uncomment the following line to use the type annotations compiler. -->
                        <!-- <arg>-J-Xbootclasspath/p:${typeAnnotationsJavac}</arg> -->
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

gude...@gmail.com

unread,
Feb 10, 2017, 5:14:22 PM2/10/17
to Checker Framework Developers, pio...@gmail.com
I am also having this issue.

Michael Ernst

unread,
Feb 10, 2017, 5:22:45 PM2/10/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
Dear gudenaua,

I'm sorry you are having trouble.
We would like to help you, but we cannot do so based on incomplete or
vague information.
Can you give us more information?

For example, what were the exact steps you took to install the Checker
Framework?

Also, please provide us enough files to reproduce your problem, such as
the source code of a project along with the exact pom.xml, and the exact
command you ran.

Please also give the full output, not just a snippet of it.

All this will help us understand and diagnose your problem.

Instructions for reporting problems appear in the manual:
https://checkerframework.org/manual/#reporting-bugs

-Mike


> Subject: Re: Can't get annotated JDK to work
> From: gude...@gmail.com
> To: Checker Framework Developers <checker-fr...@googlegroups.com>
> Date: Fri, 10 Feb 2017 14:08:57 -0800 (PST)
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to checker-framewor...@googlegroups.com.
> To post to this group, send email to
> checker-fr...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/checker-framework-dev.
> For more options, visit https://groups.google.com/d/optout.

gude...@gmail.com

unread,
Feb 11, 2017, 6:30:28 PM2/11/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
I am using IntelliJ IDEA Ultimite version 2016.3.4, I am using this POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   
<modelVersion>4.0.0</modelVersion>


   
<groupId>net.gudenau.test</groupId>
   
<artifactId>AnnotationTest</artifactId>
   
<packaging>pom</packaging>
   
<version>1.0-SNAPSHOT</version>


   
<build>
       
<plugins>
           
<plugin>
               
<!-- This plugin will set properties values using dependency information -->
                <groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-dependency-plugin</artifactId>
               
<version>2.3</version>
               
<executions>
                   
<execution>
                       
<goals>
                           
<goal>properties</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
           
<plugin>

               
<artifactId>maven-compiler-plugin</artifactId>
               
<version>3.5.1</version>
               
<configuration>
                   
<!-- Change source and target to 1.7 if using Java 7 -->
                    <source>1.8</source>
                   
<target>1.8</target>
                   
<fork>true</fork>
                   
<annotationProcessors>

                       
<!-- Add all the checkers you want to enable here -->
                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                   
</annotationProcessors>
                   
<compilerArgs>
                       
<!-- location of the annotated JDK, which comes from a Maven dependency -->
                        <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
                       
<!-- Uncomment the following line to use the type annotations compiler. -->
                        <!-- <arg>-J-Xbootclasspath/p:${typeAnnotationsJavac}</arg> -->
                    </compilerArgs>
               
</configuration>
           
</plugin>
       
</plugins>
   
</build>


   
<dependencies>
       
<!-- annotations from the Checker Framework: nullness, interning, locking, ... -->
        <dependency>
           
<groupId>org.checkerframework</groupId>
           
<artifactId>checker-qual</artifactId>
           
<version>2.1.8</version>

       
</dependency>
       
<dependency>
           
<groupId>org.checkerframework</groupId>
           
<artifactId>checker</artifactId>

           
<version>2.1.8</version>

       
</dependency>
       
<!-- The type annotations compiler - uncomment if desired -->
        <dependency>
           
<groupId>org.checkerframework</groupId>
           
<artifactId>compiler</artifactId>

           
<version>2.1.8</version>
       
</dependency>

       
<!-- The annotated JDK to use (change to jdk7 if using Java 7) -->
        <dependency>
           
<groupId>org.checkerframework</groupId>
           
<artifactId>jdk8</artifactId>

           
<version>2.1.8</version>
       
</dependency>
   
</dependencies>


   
<properties>
       
<!-- These properties will be set by the Maven Dependency plugin -->
        <!-- Change to jdk7 if using Java 7 -->
        <annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
       
<!-- Uncomment to use the type annotations compiler. -->
        <typeAnnotationsJavac>${org.checkerframework:compiler:jar}</typeAnnotationsJavac>

   
</properties>
</project>
This is the only error I get:
Auto Generated Inline Image 1

Michael Ernst

unread,
Feb 11, 2017, 6:41:40 PM2/11/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
Please reproduce the problem from the command line rather than sending us
an IntelliJ screenshot. If you cannot reproduce it from the command line,
then the problem is with IntelliJ.

Also, I saved the pom.xml you sent me in a new, empty directory and ran

mvn compile

which did not fail. Is there perhaps some source code that you forgot to
include? Please attach (don't paste) all of the files that are necessary
to reproduce the problem. Please follow the instructions at

https://checkerframework.org/manual/#reporting-bugs

which are pretty clear about this.

Thanks. We want to help you, but need information from you in order to do
so.

-Mike

> Subject: Re: Can't get annotated JDK to work
> From: gude...@gmail.com
> To: Checker Framework Developers <checker-fr...@googlegroups.com>
> Date: Sat, 11 Feb 2017 13:37:05 -0800 (PST)
> *
> > an email to checker-framewor...@googlegroups.com.
> > To post to this group, send email to
> > checker-fr...@googlegroups.com.
> > Visit this group at
> > https://groups.google.com/group/checker-framework-dev.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to checker-framewor...@googlegroups.com.

gude...@gmail.com

unread,
Feb 11, 2017, 10:25:46 PM2/11/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
Seems to be an issue with Idea not seeing the variables that the plugin sets, I'll see if I can get a feature request for that in.

Now, I am passing null to an javax.annotation.Nonnull annotated type in a method and it does not seem to catch the error when running "mvn compile", anything I need to change? I am not seeing anything about needing to enable errors for that, I would like for it to error out if possible.

Thanks for the help.
>     > To post to this group, send email to
>     > checker-fr...@googlegroups.com.
>     > Visit this group at
>     > https://groups.google.com/group/checker-framework-dev.
>     > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send

Michael Ernst

unread,
Feb 12, 2017, 10:50:06 PM2/12/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
> Seems to be an issue with Idea not seeing the variables that the plugin
> sets, I'll see if I can get a feature request for that in.

Thanks for verifying that this is an issue with IDEA.
If there is something that IDEA users need to do in general, please let us
know.
(I presume you are using the instructions at
https://checkerframework.org/manual/#intellij .)

> Now, I am passing null to an javax.annotation.Nonnull annotated type in
> a method and it does not seem to catch the error when running "mvn
> compile", anything I need to change? I am not seeing anything about
> needing to enable errors for that, I would like for it to error out if
> possible.

Are you following the Maven instructions at
https://checkerframework.org/manual/#maven ? That's what I use and it
works for me. If you can provide a test case that reproduces the issue,
we'll be happy to look into it.

-Mike

gude...@gmail.com

unread,
Feb 13, 2017, 6:03:52 PM2/13/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
I did use the Maven setup, but passing null when using "mvn compile" is not caught.

Something like this is not caught.
public static void test(@Nonnull Object para){

}
public static void main(String[] arguments){
    test(null);

Michael Ernst

unread,
Feb 13, 2017, 6:15:22 PM2/13/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
I'm sorry to hear it. Can you please provide a complete test case? Then
we'll look into what is different between your setup and that one.
(Alternately, I could create an example Maven project and you could
investigate the differences between your setup and that one.)

-Mike

> Subject: Re: Can't get annotated JDK to work
> From: gude...@gmail.com
> To: Checker Framework Developers <checker-fr...@googlegroups.com>
> Date: Mon, 13 Feb 2017 14:10:41 -0800 (PST)
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to checker-framewor...@googlegroups.com.

gude...@gmail.com

unread,
Feb 13, 2017, 11:44:00 PM2/13/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
I was messing with my dependencies in a multi-module project and it just started catching the errors. Not sure what I did to fix it, but I am glad that it is working now!

Michael Ernst

unread,
Feb 13, 2017, 11:53:31 PM2/13/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
Great! Let us know if there is information you learn that we should put
in the manual.

-Mike


> Subject: Re: Can't get annotated JDK to work
> From: gude...@gmail.com
> To: Checker Framework Developers <checker-fr...@googlegroups.com>
> Date: Mon, 13 Feb 2017 18:00:15 -0800 (PST)
> > an email to checker-framewor...@googlegroups.com.
> > To post to this group, send email to
> > checker-fr...@googlegroups.com.
> > Visit this group at
> > https://groups.google.com/group/checker-framework-dev.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to checker-framewor...@googlegroups.com.

gude...@gmail.com

unread,
Feb 14, 2017, 3:11:25 PM2/14/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
One more thing, I am using reflection and java.lang.reflect.Field.get is causing errors when passing null.

found: null
required: @Initialized @NonNull Object

This seems to be in error, because you pass null for static fields.
>     > To post to this group, send email to
>     > checker-fr...@googlegroups.com.
>     > Visit this group at
>     > https://groups.google.com/group/checker-framework-dev.
>     > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send

Michael Ernst <michael.ernst@alum.mit.edu>

unread,
Feb 14, 2017, 4:18:20 PM2/14/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
Sorry, but this vague report doesn't help me to understand what you have
done, nor to verify that a fix improves the situation. Whenever you
report a problem, please give complete information to enable someone else
to reproduce your problem without guessing.

Note that Field.get is annotated as taking a nullable argument in the JDK:
@SideEffectFree public @Nullable Object get(@UnknownInitialization @Raw
@Nullable Object obj) throws IllegalArgumentException,
IllegalAccessException { ... }

Thank you for helping us to help you.

-Mike


> Subject: Re: Can't get annotated JDK to work
> From: gude...@gmail.com
> To: Checker Framework Developers <checker-fr...@googlegroups.com>
> Date: Tue, 14 Feb 2017 08:51:36 -0800 (PST)
> > > an email to checker-framewor...@googlegroups.com.
> > > To post to this group, send email to
> > > checker-fr...@googlegroups.com.
> > > Visit this group at
> > > https://groups.google.com/group/checker-framework-dev.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Checker Framework Developers" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to checker-framewor...@googlegroups.com.
> > To post to this group, send email to
> > checker-fr...@googlegroups.com.
> > Visit this group at
> > https://groups.google.com/group/checker-framework-dev.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to checker-framewor...@googlegroups.com.

gude...@gmail.com

unread,
Feb 16, 2017, 12:20:22 AM2/16/17
to Checker Framework Developers, gude...@gmail.com, pio...@gmail.com
One example:

import sun.misc.Unsafe;

import javax.annotation.Nullable;
import java.lang.reflect.Field;

public class
UnsafeHelper {
   
@Nullable
    private static Unsafe unsafe;

   
public static Unsafe getUnsafe(){
       
if(unsafe != null){
           
return unsafe;
       
}

       
for(Field field : Unsafe.class.getDeclaredFields()){
           
if(field.getType() == Unsafe.class){
               
try {
                    field
.setAccessible(true);
                   
unsafe = (Unsafe)field.get(null);
                   
if(unsafe != null){
                       
return unsafe;
                   
}
               
} catch (ReflectiveOperationException e) {
                   
throw new RuntimeException("Could not read Unsafe instance!", e);
               
}
           
}
       
}

       
throw new RuntimeException("Could not find Unsafe instance!");
   
}
}

Then Idea spits out:
Error:(79, 48) java [argument.type.incompatible] incompatible types in argument.

    found : null
    required: @Initialized @NonNull Object

But the "mvn compile" command works, more Idea weirdness I suppose?
>     > > To post to this group, send email to
>     > > checker-fr...@googlegroups.com.
>     > > Visit this group at
>     > > https://groups.google.com/group/checker-framework-dev.
>     > > For more options, visit https://groups.google.com/d/optout.
>     >
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "Checker Framework Developers" group.
>     > To unsubscribe from this group and stop receiving emails from it,
> send
>     > To post to this group, send email to
>     > checker-fr...@googlegroups.com.
>     > Visit this group at
>     > https://groups.google.com/group/checker-framework-dev.
>     > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Checker Framework Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send

Michael Ernst

unread,
Feb 17, 2017, 12:36:34 PM2/17/17
to gudenaua, Checker Framework Developers, pio...@gmail.com
Thanks for the test case.

> Idea spits out:
> Error:(79, 48) java [argument.type.incompatible] incompatible types in
> argument.
> found : null
> required: @Initialized @NonNull Object
>
> But the "mvn compile" command works, more Idea weirdness I suppose?

This looks like an Idea problem.

I saved the attached file (same as yours) as UnsafeHelper.java, then ran

$CHECKERFRAMEWORK/checker/bin/javac -g UnsafeHelper.java -processor
nullness

I received multiple warnings
"warning: Unsafe is internal proprietary API and may be removed in a
future release"
but no warnings from the Nullness Checker. So, it seems that the nullness
checker is working properly from the command line (and presumably from
your Maven invocation), but differently from Idea.

Sorry, I have no concrete idea of what the problem might be.

-Mike
UnsafeHelper.java

Werner Dietl

unread,
Feb 17, 2017, 11:36:18 PM2/17/17
to Michael Ernst, gudenaua, Checker Framework Developers, pio...@gmail.com
Given that this works as expected on the command-line I would check
whether the annotated JDK jar file is added correctly to the IDEA
bootclasspath. Make sure that the jdk8.jar is on the bootclasspath
before the rt.jar file.
Did you follow step 3 of https://checkerframework.org/manual/#intellij ?
cu, WMD.
> import java.lang.reflect.Field;
> import org.checkerframework.checker.nullness.qual.Nullable;
> import sun.misc.Unsafe;
>
> public class UnsafeHelper {
> @Nullable private static Unsafe unsafe;
>
> public static Unsafe getUnsafe() {
> if (unsafe != null) {
> return unsafe;
> }
>
> for (Field field : Unsafe.class.getDeclaredFields()) {
> if (field.getType() == Unsafe.class) {
> try {
> field.setAccessible(true);
> unsafe = (Unsafe) field.get(null);
> if (unsafe != null) {
> return unsafe;
> }
> } catch (ReflectiveOperationException e) {
> throw new RuntimeException("Could not read Unsafe instance!", e);
> }
> }
> }
>
> throw new RuntimeException("Could not find Unsafe instance!");
> }
> }
>



--
http://www.google.com/profiles/wdietl

psequ...@gmail.com

unread,
Nov 5, 2018, 9:57:59 AM11/5/18
to Checker Framework Developers
I have found that IntelliJ is unable to properly translate the expression ${org.checkerframework:jdk8:jar} when importing the build config from the pom.xml.

The way I was able to work around this is by defining the annotatedJdk property as follows:

<checkerframework.version>2.5.6</checkerframework.version>
<annotatedJdk>${settings.localRepository}/org/checkerframework/jdk8/${checkerframework.version}/jdk8-${checkerframework.version}.jar</annotatedJdk>

After that both, the mvn command line and the IntelliJ builds, started to work as expected.

Note that, by not using the dependency expression, it's no longer necessary to configure the maven-dependency-plugin either as suggested in https://checkerframework.org/manual/#maven

On Saturday, February 11, 2017 at 5:30:28 PM UTC-6, gude...@gmail.com wrote:
I am using IntelliJ IDEA Ultimite version 2016.3.4, I am using this POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

...
Reply all
Reply to author
Forward
0 new messages