Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is groovy-eclipse project compatible with checker-framework? #799

Closed
croesch opened this issue Jan 24, 2019 · 12 comments
Closed

Is groovy-eclipse project compatible with checker-framework? #799

croesch opened this issue Jan 24, 2019 · 12 comments
Assignees
Labels

Comments

@croesch
Copy link

croesch commented Jan 24, 2019

Hello we'd like to run some spock tests but we're also using checker-framework.

We have trouble to get the project run. Basically we posted the information on stackoverflow yesterday.

Basic question is: Is groovy-eclipse project compatible with checker-framework?

If yes: What am I doing wrong / how can I solve my issues?

Could somebody have a look at the question, I'd like to avoid redundancy but I feel like nobody could easily answer the question - so maybe you could help me. If necessary I can repost everything here :)

Thanks in advance.

@croesch
Copy link
Author

croesch commented Jan 24, 2019

Currently we're using Java 7. Newest versions of the frameworks require Java 8 as far as I can see - but the problem still exists in newer (-compiler 3.0.0-02 + -batch 2.4.16-02) versions.

@eric-milles
Copy link
Member

@croesch Could you attach your sample maven project zip (or a link to it on github)? Also do you have a java-only example that works so I could compare? I can take a look from there.

Java 8 is required to use newer batch compiler, but you still should be able to target Java 7 with no issue.

@croesch
Copy link
Author

croesch commented Jan 24, 2019

Thanks for the quick reply, I uploaded the project files croesch/groovy-spock-checkerframework-test.

Please note that the application doesn't use any spock or checkerframework features currently. It's just about compiling an empty repository - if you would like some source code that uses either checkerframework or spock features, let me know - but at the current stage I think this is not necessary.

Branch only-checkerframework contains the SUCCESS-bringing POM using only the checker-framework.

Branch spock-groovy-checkerframework contains the FAILURE-bringing POM.

EDIT run the verification (with checkerframework) via $ mvn clean verify -Pcheckerframework

@eric-milles
Copy link
Member

eric-milles commented Jan 24, 2019

I was able to get the compler and tests to run successfully with this POM. I tried to remove some of the extra property indirection. This assumes Java for sources and Groovy/Java for tests. It is using the latest checker-framework; you should be able to go back to the Java 7 compatible version with a few edits.

<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>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.fork>true</maven.compiler.fork>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <org.checkerframework.version>2.6.0</org.checkerframework.version>
  </properties>

  <pluginRepositories>
    <pluginRepository>
      <id>bintray</id>
      <name>Groovy Bintray</name>
      <url>https://dl.bintray.com/groovy/maven</url>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.checkerframework</groupId>
      <artifactId>checker-qual</artifactId>
      <version>${org.checkerframework.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>1.2-groovy-2.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <!-- Any config specific to main compile -->
            </configuration>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <compilerId>groovy-eclipse-compiler</compilerId>
              <compilerArgument>-proc:none</compilerArgument>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>3.3.0-01</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.4.16-02</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>checker</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>

      <dependencies>
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>jdk8</artifactId>
          <version>${org.checkerframework.version}</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>properties</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
              <execution>
                <id>default-compile</id>
                <configuration><!-- https://checkerframework.org/manual/#maven -->
                  <annotationProcessors>
                    <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                  </annotationProcessors>
                    <annotationProcessorPath>
                      <groupId>org.checkerframework</groupId>
                      <artifactId>checker</artifactId>
                      <version>${org.checkerframework.version}</version>
                    </annotationProcessorPath>
                  </annotationProcessorPaths>
                  <compilerArgument>-Xbootclasspath/p:${org.checkerframework:jdk8:jar}</compilerArgument>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>

@eric-milles eric-milles self-assigned this Jan 24, 2019
@croesch
Copy link
Author

croesch commented Jan 24, 2019

Oh sure, I added the repository on company's proxy repo, thx for the hint. I updated the POM.

But are you sure that you run the checkerframework? You have to activate the profile

$ mvn clean verify -Pcheckerframework

I added code in both branches that will fail if the checkerframework runs. It will produce output like this:

[ERROR] /home/user/public/my-app/src/main/java/com/mycompany/app/App.java:[19,13] error: (return.type.incompatible) $$ 2 $$ @FBCBottom @Nullable  null $$ @Initialized @NonNull String $$ ( 363, 367 ) $$ incompatible types in return.
  found   : @FBCBottom @Nullable  null
  required: @Initialized @NonNull String

For me - with your updated POM - I still get the error about Internal compiler error

@eric-milles
Copy link
Member

I suspect this issue is to blame: pdurbin/maven-hello-world#3

I'm trying to follow the setup instructions for the specific checkerframework version: https://checkerframework.org/releases/2.1.14/manual/#maven

What I am finding is that passing the 2 different type of compiler arguments is difficult. ecj (aka groovy-eclipse-batch) wants "-bootclasspath" "path/to/jdk7-compat-jar" as two separate arguments and the JVM wants "-Xbootclasspath/p:${org.checkerframework:compiler:jar}" to augment the compiler classpath. I'll edit the POM above if I can get this going.

@eric-milles
Copy link
Member

eric-milles commented Jan 25, 2019

So I think I have everything wired up as best as can be hoped. The exception below is from the snippet of JavacTask. It is expecting a very specific ProcessingEnvironment type. I don't think the Eclipse compiler is supplying this -- it is likely supplying an instance of org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl.

Internal compiler error: java.lang.IllegalArgumentException at com.sun.source.util.JavacTask.instance(JavacTask.java:66)
    public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
        if (!processingEnvironment.getClass().getName().equals(
                "com.sun.tools.javac.processing.JavacProcessingEnvironment"))
            throw new IllegalArgumentException(); // line 66

(Taken from https://github.com/infobip/infobip-open-jdk-8/blob/master/langtools/src/share/classes/com/sun/source/util/JavacTask.java)

@eric-milles
Copy link
Member

One idea I had late yesterday is to split compilation into two phases. In one, you could have the traditional maven java compiler run the checkerframework with compiler argument "-proc:only". In the other, you could configure the groovy compiler adapter to skip annotation processing with compiler argument "-proc:none". This should give you both checkerframework and joint groovy/java compilation.

@croesch
Copy link
Author

croesch commented Feb 4, 2019

Thanks for the information about the different compiler arguments - did you get it working?

Is your last idea of the two-phase-compilation simple to setup because I have no experience with something like that - any way could you assist me with the final solution?

Checkerframework and groovy-compiler is both only important for testing (in my scenario), so it would be acceptable to have some setup that compiles multiple times with different compilers while testing whereas the "normal" compilation would only use the default compiler without further magic.

@eric-milles
Copy link
Member

eric-milles commented Feb 4, 2019

I edited the POM above. It should use standard maven compiler for src/main/java and this includes checker-framework processor. And it should use Groovy-Eclipse compiler adapter for src/test/groovy and src/test/java. In my case, I just put one empty text file in src/test/java and all the tests in src/test/groovy.

@croesch
Copy link
Author

croesch commented Feb 5, 2019

Thanks very much - that setup is working and I think it's an acceptable workaround.

So the answer of the original question still might be no, groovy-compiler cannot work on the same sources as the checkerframework!?

@eric-milles
Copy link
Member

Correct, the eclipse compiler is not compatible with the checker framework. This is because of the very strict type checking deep in the Java compiler supplied by the framework (see details above). If this were loosened up, ecj and therefore groovy-eclipse-batch could work with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants