Checker Framework and Lombok

759 views
Skip to first unread message

Michael Dykman

unread,
Nov 7, 2016, 12:00:32 PM11/7/16
to Checker Framework discussion
Has anyone had success using both Lombok (https://github.com/rzwitserloot/lombok) and CheckerFramework ?

I have a gradle 2.4 multi-project build under Java 8 which is using lombok (v1.16.8) to generate equals, hashCode, getters and setters (mostly on JPA @Entitys) which has been very successful. Lombok has been integrated with gradle with no unexpected side effects as all of the generated methods are visible to dependents at all stages of the compile cycle. The Lombok tool set provides an eclipse extension so that the generated methods are visible in eclipse's compiler.

Within this project, I am aready using  static_code_analysis as provided by Monits (https://plugins.gradle.org/plugin/com.monits.staticCodeAnalysis (v2.3.0))  in my buildscript which has no problems with lombok, in that it sees all of the generated methods.

When I added checker-framework (v2.1.4) to the stack (as directed by management), the compiler now no longer sees any of the lombok-generated methods and causes a lot of errors to be thrown.

Werner Dietl

unread,
Nov 7, 2016, 1:25:45 PM11/7/16
to Michael Dykman, Checker Framework discussion
Hi Michael,

thanks for your comments and I'm sorry you're running into trouble.
Can you share a minimal project that illustrates the build issue?
I've not used the static_code_analysis plug-in by Monits, but I'm sure
we can get this working.

cu, WMD.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Checker Framework discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to checker-framework-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



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

Michael Dykman

unread,
Nov 7, 2016, 5:23:26 PM11/7/16
to Checker Framework discussion, mdy...@gmail.com
Hi Werner,

Here is the smallest representation that I can manage.  As I am using gradle (3.1, same results under 2.4) and the issue is a build issue, the problem is presenting itself as necessarily a gradle problem.

To be clear, I do not suspect any conflict between CheckerFramework and montis static_code_analysis, so I have left the latter out of this example.

Listed towards the end of this message are a very simple Java file and a slightly less simple gradle.build file using lombok which demonstrates the problem.  Lombok, through the medium of the @Data annotation, generates setters and getters for package-protected members 'foo' and 'bar'.
If this is built with the gradle.build file listed below (with the last 10 lines commented out, effectively disabling CheckerFramework as indicated here), it works fine.

$ ./gradlew build
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 1.302 secs

$ java -cp build/libs/demo-conflict.jar org.test.Test
test has foo = 5, bar = BAR

My IDE (eclipse-neon), having been prepared for lombok via https://projectlombok.org/download.html also registers no issues


If I enable CheckerFramework by removing the comments around that last block, the build looks like this:

$ ./gradlew build
:compileJavaC:\Users\mdykman\projects\mergespace\demo-conflict\src\main\java\org\test\Test.java:14: error: cannot find symbol
                System.out.println(String.format("test has foo = %d, bar = %s",test.getFoo(),test.getBar()));
                                                                                   ^
  symbol:   method getFoo()
  location: variable test of type Test
C:\Users\mdykman\projects\mergespace\demo-conflict\src\main\java\org\test\Test.java:14: error: cannot find symbol
                System.out.println(String.format("test has foo = %d, bar = %s",test.getFoo(),test.getBar()));
                                                                                                 ^
  symbol:   method getBar()
  location: variable test of type Test
2 errors
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.749 secs


======== Test.java =======
package org.test;


import lombok.Data;

@Data
public class Test {
        int foo = 5;
        String bar="BAR";

        public static void main(String[] args) {
                Test test = new Test();

                System.out.println(String.format("test has foo = %d, bar = %s",test.getFoo(),test.getBar()));
        }

}
============= end of Test.java ==============

Here is my minimum gradle.build file.  The interesting part is found in the last 10 lines.
========== build.gradle ============
apply plugin: 'java'
apply plugin: 'eclipse'

repositories {
    jcenter()
}

   ext.checkerFrameworkVersion = '2.1.4'
   ext.jdkVersion = 'jdk8'
   ext.targetJavaVersion = JavaVersion.VERSION_1_8

configurations {
        checkerFrameworkJavac {
                description = 'a customization of the OpenJDK javac compiler with additional support for type annotations'
        }
        checkerFrameworkAnnotatedJDK {
         description = 'a copy of JDK classes with Checker Framework type qualifers inserted'
        }
        checkerFramework {
         description = 'The Checker Framework: custom pluggable types for Java'
        }
}

dependencies {
        compile group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
        compile group: 'org.checkerframework', name: 'checker', version:  checkerFrameworkVersion

        checkerFrameworkAnnotatedJDK "org.checkerframework:${jdkVersion}:${checkerFrameworkVersion}"
        checkerFramework "org.checkerframework:checker:${checkerFrameworkVersion}"

        compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"

}
  /*
tasks.withType(JavaCompile).all { JavaCompile compile ->
   compile.options.compilerArgs = [
       '-processor', 'org.checkerframework.checker.nullness.NullnessChecker',
       '-processorpath', "${configurations.checkerFramework.asPath}",
          // uncomment to turn Checker Framework errors into warnings
          //      '-Awarns',
       "-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}"
        ]
}
   */



Michael Dykman

unread,
Nov 8, 2016, 9:50:52 AM11/8/16
to Checker Framework discussion
It gradually dawned on me that CheckerFramewok is running an annotation pre-processors which, using the default configuration instructions, excludes other annotation pre-processors from running.  After a little googling and trial and error I modified my build.gradle file to the following and my build lives again!

Adding lombok to the CheckerFramework classpath and appending it's annotation processor to the list was all that was needed.

==== build.gradle ====

apply plugin: 'java'
apply plugin: 'eclipse'

repositories {
    jcenter()
}


   ext.checkerFrameworkVersion = '2.1.4'
   ext.jdkVersion = 'jdk8'
   ext.targetJavaVersion = JavaVersion.VERSION_1_8


configurations {
   checkerFrameworkJavac {
      description = 'a customization of the OpenJDK javac compiler with additional support for type annotations'
   }
   checkerFrameworkAnnotatedJDK {
         description = 'a copy of JDK classes with Checker Framework type qualifers inserted'
   }
   checkerFramework {
         description = 'The Checker Framework: custom pluggable types for Java'
   }
}

dependencies {
   compile group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
// add the package of my 'other' preprocessor to the checker classpath
   checkerFramework group: 'org.projectlombok', name: 'lombok', version: '1.16.8'

   compile group: 'org.checkerframework', name: 'checker', version:  checkerFrameworkVersion

   checkerFrameworkAnnotatedJDK "org.checkerframework:${jdkVersion}:${checkerFrameworkVersion}"
   checkerFramework "org.checkerframework:checker:${checkerFrameworkVersion}"

   compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"

}

   tasks.withType(JavaCompile).all { JavaCompile compile ->
        compile.options.compilerArgs = [
// add the lombok pre-processor to the list
                '-processor', 'org.checkerframework.checker.nullness.NullnessChecker,lombok.launch.AnnotationProcessorHider$AnnotationProcessor',
               '-processorpath', "${configurations.checkerFramework.asPath}",
                // uncomment to turn Checker Framework errors into warnings
                '-Awarns',
                "-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}"
        ]
    }

danielmalc...@gmail.com

unread,
Dec 12, 2016, 9:57:41 AM12/12/16
to Checker Framework discussion
Hi,

I've been looking into this as well (why I found this thread), and I can't get it to work.  I've copied your minimal example, and it doesn't build for me (TBF, I put in an invalid @NonNull so it shouldn't build, but it's not getting that far).  At the moment I'm only using lombok, but I'd really like to use the checker framework as well.

The code I copied from the minimal example above is at https://github.com/dabraham02124/lombokChecker can someone please tell me what I'm doing wrong?

If someone can help me with this, I'd appreciate it immensely.  Thank you very much.

faraz....@googlemail.com

unread,
Jul 21, 2017, 12:51:17 PM7/21/17
to Checker Framework discussion, mdy...@gmail.com
Does anyone know whether there are still problems with using lombok and checker framework together? 

thx

Ram Anvesh Reddy

unread,
Feb 9, 2021, 10:20:52 PM2/9/21
to Checker Framework discussion
Thank you for sharing this.

For those intereseted in Maven, adding the below highlighted blocks solved it for me..

```
<annotationProcessorPaths>
<path>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>3.10.0</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</path>
</annotationProcessorPaths>
```
and
```
<annotationProcessors>
<!-- Add all the checkers you want to enable here -->
<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
</annotationProcessors>
```
Reply all
Reply to author
Forward
0 new messages