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

Checker not working on Java 7 #3

Open
pdurbin opened this issue Aug 21, 2015 · 19 comments
Open

Checker not working on Java 7 #3

pdurbin opened this issue Aug 21, 2015 · 19 comments

Comments

@pdurbin
Copy link
Owner

pdurbin commented Aug 21, 2015

Checker is working great with Java 8 (see 3c08628) but I can't get it working with Java 7.

Locally I made the following change to the pom.xml to switch from Java 8 to Java 7...

[pdurbin@tabby my-app]$ git diff
diff --git a/my-app/pom.xml b/my-app/pom.xml
index d998204..9e64242 100644
--- a/my-app/pom.xml
+++ b/my-app/pom.xml
@@ -10,7 +10,7 @@

   <properties>
       <!-- This property will be set by the Maven Dependency plugin -->
-      <annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
+      <annotatedJdk>${org.checkerframework:jdk7:jar}</annotatedJdk>
   </properties>

   <dependencies>
@@ -32,7 +32,7 @@
     </dependency>
     <dependency>
         <groupId>org.checkerframework</groupId>
-        <artifactId>jdk8</artifactId>
+        <artifactId>jdk7</artifactId>
         <version>1.9.4</version>
     </dependency>
   </dependencies>
@@ -92,8 +92,8 @@
       <plugin>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
-              <source>1.8</source>
-              <target>1.8</target>
+              <source>1.7</source>
+              <target>1.7</target>
               <fork>true</fork>
               <!-- Add all the checkers you want to enable here -->
               <annotationProcessors>
[pdurbin@tabby my-app]$ 

... but it's not working. I'm getting this error:

[pdurbin@pdurbin my-app]$ mvn package -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 92, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.3:properties (default) @ my-app ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/pdurbin/github/pdurbin/maven-hello-world/my-app/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ my-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/pdurbin/github/pdurbin/maven-hello-world/my-app/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.560 s
[INFO] Finished at: 2015-08-21T18:33:59-04:00
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-app: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-app: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:862)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[pdurbin@tabby my-app]$ 
@pdurbin
Copy link
Owner Author

pdurbin commented Aug 22, 2015

I'm not quite ready to move different project from Java 7 to Java 8 so I enabled Checker in a branch for now: pdurbin/addressbookmvc@0839841

@renatoathaydes
Copy link

I had a look and it seems to me the jdk7 Maven artifact was compiled with Java 8, therefore it won't work if you compile your project with Java 7.

The error I got here was this:

[ERROR] error: InvocationTargetException when invoking constructor for class
 org.checkerframework.checker.nullness.KeyForVisitor; Underlying cause: 
InvocationTargetException when invoking constructor for class
 org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory; 

Underlying cause: com.sun.tools.javac.code.Symbol$CompletionFailure: 
class file for java.util.TimeZone$DisplayNames not found; 
invoke the compiler with -AprintErrorStack to see the stack trace.

Could you guys please make sure you compile the jdk7 jar with a Java 7 compiler?

@renatoathaydes
Copy link

Sorry, it seems it was ME who was using Java 8's javac :(

Anyway, I got to try to compile the code using javac rather than Maven and got the root error:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchMethodError: com.sun.source.util.JavacTask.instance(Ljavax/annotation/processing/ProcessingEnvironment;)Lcom/sun/source/util/JavacTask;
    at org.checkerframework.javacutil.AbstractTypeProcessor.init(AbstractTypeProcessor.java:119)
    at org.checkerframework.framework.source.SourceChecker.init(SourceChecker.java:393)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:517)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:614)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:707)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    at com.sun.tools.javac.main.Main.compile(Main.java:353)
    at com.sun.tools.javac.main.Main.compile(Main.java:342)
    at com.sun.tools.javac.main.Main.compile(Main.java:333)
    at com.sun.tools.javac.Main.compile(Main.java:76)
    at com.sun.tools.javac.Main.main(Main.java:61)

Clearly, the error is at AbstractTypeProcessor.java:119. It's trying to use some method that does not exist in the Oracle VM (as of version 1.7.0_80).

@renatoathaydes
Copy link

My whole session, just in case you find it hard to reproduce:

renato@renato ~/programming/java/checker-maven-demo $ javac -version
javac 1.7.0_80
renato@renato ~/programming/java/checker-maven-demo $ javac -classpath /home/renato/programming/java/checker-maven-demo/target/classes:/home/renato/.m2/repository/org/checkerframework/checker/1.9.3/checker-1.9.3.jar:/home/renato/.m2/repository/org/checkerframework/checker-qual/1.9.3/checker-qual-1.9.3.jar:/home/renato/.m2/repository/org/checkerframework/jdk7/1.9.3/jdk7-1.9.3.jar: -sourcepath /home/renato/programming/java/checker-maven-demo/src/main/java:/home/renato/programming/java/checker-maven-demo/target/generated-sources/annotations: /home/renato/programming/java/checker-maven-demo/src/main/java/com/athaydes/checkerframework/NullnessExample.java -s /home/renato/programming/java/checker-maven-demo/target/generated-sources/annotations -processor org.checkerframework.checker.nullness.NullnessChecker -g -target 1.7 -source 1.7 -Xbootclasspath/p:/home/renato/.m2/repository/org/checkerframework/jdk7/1.9.3/jdk7-1.9.3.jar

pdurbin referenced this issue in typetools/checker-framework Aug 22, 2015
…ramework!

Only slight adaptations afterwards.
pdurbin added a commit that referenced this issue Aug 22, 2015
On Ubuntu:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 mvn package
@pdurbin
Copy link
Owner Author

pdurbin commented Aug 22, 2015

@renatoathaydes good sleuthing. For now I left a comment for @wmdietl typetools/checker-framework@1737b00#commitcomment-12843853

This how I'm able to reproduce the bug... by compiling the application with the javac from Java 7: JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 mvn package

I just pushed a branch to test from (uses Java 7 instead of Java 8): https://github.com/pdurbin/maven-hello-world/commits/java7checker

@wmdietl
Copy link

wmdietl commented Aug 22, 2015

Hi Philip, Renato,
I added a comment to your question:

typetools/checker-framework@1737b00#commitcomment-12844274

You should be able to use a Java 7 JVM, but you will need to use a Java 8 javac, either jsr308-langtools or the OpenJDK 8 javac.
cu, WMD.

@pdurbin
Copy link
Owner Author

pdurbin commented Aug 31, 2015

@wmdietl thanks! It would probably be much more straightforward for your potential users to tell them that they must use Java 8. I find "Requirement: You must have JDK 7 or later installed" at http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#installation a little misleading. Here's the line in question:

https://github.com/typetools/checker-framework/blob/checker-framework-1.9.3/checker/manual/introduction.tex#L197

I believe you that jsr308-langtools (whatever that is) helps Checker work with Java 7 but if I'd humbly suggest changing the line above to suggest that new users start with Java 8 since Java 7 is EOL these days anyway.

@wmdietl
Copy link

wmdietl commented Sep 1, 2015

There are still many of our users that depend on Java 7. If you follow the instructions you cite, you can successfully and without hassle use the Checker Framework with Java 7.
jsr308-langtools is distributed with the Checker Framework release and used by all distributed scripts.
If you want to not use jsr308-langtools you need to change your configuration and use a Java 8 javac instead.

@pdurbin
Copy link
Owner Author

pdurbin commented Sep 1, 2015

@wmdietl already the section about Maven indicates that Java 8 should be used. Or at least it suggests it with 1.8 specified for the maven-compiler-plugin: http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#maven . The Maven section doesn't say anything about Java 7 or jsr308-langtools (though the Ant section mentions "Set the jsr308javac property".)

Anyway, it seems like a hassle to use Checker with Java 7 and Maven. That's fine. We should all be upgrading to Java 8 anyway! :)

@renatoathaydes
Copy link

Using the Checker Framework as it stands is a hassle with Java 7 or Java 8, which explains why it is not being widely used (can't find any blog posts, questions about it on StackOverflow etc.). It's a pitty.

To succeed, Checker should be and behave just like an annotation processor which does some static checks at compile-time, and that's what I was trying to use it as (and succeeded for the most part, but it was a hassle for sure). I will not use some unknown, slow compiler on my code. I want the nullness checks to be optional. We have lots of legacy modules which we will not use nullness checks on. I don't want to manually download and install what is basically a Java library as in pre-Maven times. And most people won't do that either, I'd think. Because that shouldn't be necessary.

A little more focus on convenience would go a long way.

@wmdietl
Copy link

wmdietl commented Sep 1, 2015

@pdurbin @renatoathaydes @mernst @JonathanBurke
I'm sorry to hear that you're running into such troubles using the Checker Framework.

The Checker Framework is an annotation processor and using it as such is possible. We provide scripts to make usage as convenient as possible, for the users we hear from.
If you have concrete suggestions for what can be improved - either in documentation, scripts, or examples, do let us know.

jsr308-langtools is a clone of Java 8u javac - it is not "some unknown, slow compiler". The slowdown is purely due to the checks the Checker Framework performs as an annotation processor. The reason to have jsr308-langtools is to support our existing users that require Java 7 compatibility - by providing support for the new type annotation syntax in comments.

The nullness checks are completely optional. Can you elaborate why you think they are not?

@pdurbin
Copy link
Owner Author

pdurbin commented Sep 1, 2015

No trouble with Java 8 and Maven! Checker is great! I've been trying to explain it to people: http://irclog.greptilian.com/sourcefu/2015-08-31#i_135262 :)

@mernst
Copy link

mernst commented Sep 2, 2015

Cool, I'm glad it is working for you. Lots of folks report similar success.

I'm hoping that Renato can explain how he came about his mistaken beliefs, so that we can improve the documentation and so that he can be successful too. Thanks in advance, Renato, for helping us help you.

@renatoathaydes
Copy link

Well, I created the project which makes Maven and Java8 work well together (this is a fork of that). The guide in the current documentation tells me I have to download Checker, when that really shouldn't be the case, and I have an open PR which changes the guide to make it easier (though not easy still) for people.

My beliefs are not mistaken in any way, it is a hassle to use Checker. My colleagues think I'm crazy for even trying. IF you don't see that, then you seem to be the one with mistaken beliefs.

Using an annotation processor should consist of:

  • add the dependencies in the pom
  • add the instruction adding the annotation processor in the compiler configuration

My PR almost achieves that... we still need to go through hoops to get the annotated JDK's path given to the compiler (which is more a fault of Maven than Checker, admittedly)

If you want to help me, merge my PR, fix the problems you guys raised with it (really minor ones but I've been too busy lately) and try to make it even easier by not requiring the annotated JDK path (I've already suggested in another thread you should use stubs instead, but I was dismissed), please.

EDIT

I've been trying to help you make your project attractive to professional developers who would otherwise just ignore your project as soon as they see how it relies on installation of local files and relative paths to find things to be used. Any non-academic/non-single-person project will have a build that runs on dozens of machines where you can't just install things that are not part of the toolchain and use relative paths to connect them. If you, like me, think the Checker Framework can be useful for professionals, and is not just an academic exercise, try to accept my criticism constructively. I don't need help with anything, I have everything I need working beautifully, as always :) I don't benefit in any way by pointing out issues I see with Checker and solutions to try to make it better. But I do so anyway because I believe it's worth it in this case. If you think what you're doing is perfect and anyone criticising obviously has mistaken beliefs, then good luck with that attitude, but I hope that's not the case.

@pdurbin
Copy link
Owner Author

pdurbin commented Sep 2, 2015

I do hope that @mernst and @wmdietl appreciate where @renatoathaydes is coming from. I really appreciate the work he's done in typetools/checker-framework#461 and https://github.com/renatoathaydes/checker-maven-demo . It has inspired me to play with Checker more. Perhaps some day I'll try to introduce it to my team.

@mernst maybe you can elaborate on what you mean by "mistaken beliefs."

@mernst
Copy link

mernst commented Sep 2, 2015

Renato, we do appreciate all your help and the effort you have put in. I've said it before and I will say it again: Thanks!

I completely accept that the Maven integration must be improved because it is currently a hassle to use. We appreciate your help with it. As you point out, some of the problems are due to Maven itself, some due to our requirement to support Java 7, and some due to the current poor status of our existing Maven support.

I agree that in principle all Java users ought to move to Java 8, but we have many commercial users who are stuck on Java 7 and any solution needs to work for them too. That's why we cannot accept a solution that only works for Java 8. Our roadmap has us requiring Java 8 in April 2016.

The beliefs I was referring to were "I will not use some unknown, slow compiler on my code. I want the nullness checks to be optional." Werner specifically asked about both of these, but I didn't see an answer to his questions. For example, could you tell us why you believe the nullness checks are not optional, so that we can improve the documentation?

Thanks again for your help.

@pdurbin
Copy link
Owner Author

pdurbin commented Nov 11, 2015

@mernst thanks for your kind words about @renatoathaydes and clarifying which questions are unanswered.

@mernst
Copy link

mernst commented Nov 11, 2015

@pdurbin The current Checker Framework release (version 1.9.8) includes new Maven instructions that are supposed to work with both Java 7 and Java 8 (though you do have to edit your Maven build file to switch between Java 7 and Java 8). Can you check whether they work for you and this issue can be closed?
Thanks!

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

No branches or pull requests

4 participants