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 always run in Maven also without active profile in Java11 #5086

Closed
danibs opened this issue Mar 21, 2022 · 3 comments · Fixed by #5089
Closed

Checker always run in Maven also without active profile in Java11 #5086

danibs opened this issue Mar 21, 2022 · 3 comments · Fixed by #5089

Comments

@danibs
Copy link

danibs commented Mar 21, 2022

In my project I'm using Java 11 and Maven.
I follow this https://checkerframework.org/manual/#maven and add

<dependency>
	<groupId>org.checkerframework</groupId>
	<artifactId>checker-qual</artifactId>
	<version>3.21.3</version>
	<scope>provided</scope>
</dependency>

and two profiles:

<profile>
	<id>checkerframework</id>
	<activation>
		<jdk>[1.8,)</jdk>
	</activation>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<fork>true</fork> <!-- Must fork or else JVM arguments are ignored. -->
					<compilerArguments>
						<Xmaxerrs>10000</Xmaxerrs>
						<Xmaxwarns>10000</Xmaxwarns>
					</compilerArguments>
					<annotationProcessorPaths>
						<path>
							<groupId>org.checkerframework</groupId>
							<artifactId>checker</artifactId>
							<version>3.21.3</version>
						</path>
					</annotationProcessorPaths>
					<annotationProcessors>
	                	<!-- Add all the checkers you want to enable here -->
						<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
					</annotationProcessors>
					<compilerArgs>
	               		                  <arg>-Awarns</arg> 
					          <arg>-AstubWarnIfNotFound</arg>
					          <arg>-AskipUses=org\.apache</arg>
						<arg>-AstubDebug</arg>
					</compilerArgs>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.checkerframework</groupId>
			<artifactId>checker</artifactId>
			<version>3.21.3</version>
		</dependency>
	</dependencies>
</profile>

<profile>
	<id>checkerframework-jdk9orlater</id>
	<activation>
		<jdk>[9,)</jdk>
	</activation>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<executions>
					<execution>
						<id>default-compile</id>
					</execution>
				</executions>
				<configuration>
					<fork>true</fork>
					<compilerArgs combine.children="append">
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
						<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
						<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
					</compilerArgs>
				</configuration>
			</plugin>
		</plugins>


	</build>
	<properties>
	      <!-- Needed for animal-sniffer-maven-plugin version 1.19 (version 1.20 is fixed). -->
		<animal.sniffer.skip>true</animal.sniffer.skip>
	</properties>
</profile>

When I run mvn clean package -DskipTests=true the CF do it's job also if I do not specified checkerframework profile. This is weird.

I tryed to add:

-P '!checkerframework-java11'
-P '!checkerframework-jdk9orlater'

with the same results.

It seems possible to disable CF using:

-P '!checkerframework'

So or there are something that it doesn't work or documentation si wrong.

Thanks

mernst added a commit to mernst/checker-framework that referenced this issue Mar 21, 2022
@mernst mernst linked a pull request Mar 21, 2022 that will close this issue
@mernst
Copy link
Member

mernst commented Mar 21, 2022

Thank you for pointing out that -P '!checkerframework-java11' and -P '!checkerframework-jdk9orlater' do not work. We didn't know that. Disabling the checkerframework profile is more elegant anyway.

Could you take a look at #5089 and see whether it addresses your concern?
If not, can you clarify what still needs to be fixed?

Thanks again for the bug report.

@danibs
Copy link
Author

danibs commented Mar 23, 2022

Good to fix documentation but normally if I don't specify a Maven profile... it should not be executed.
What I mean is that if I run mvn clean package then CF should not run. I should add -P checkerframework to let it run.
It's a little weird that I have to disable it with -P '!checkerframework'.
IMHO...

@mernst
Copy link
Member

mernst commented Mar 24, 2022

Thanks for pointing that out. Our philosophy is that type-checking should be run on every compilation. If it is delayed or forgotten, and then run only later, then many benefits are lost and it is also much more troublesome to correct the entrenched errors.

Other tools, such as Error Prone, give instructions to run unconditionally on every compile (they don't even provide a switch to turn it off).

Thanks again for your feedback on the manual changes. We appreciate it!

wmdietl pushed a commit to eisop/checker-framework that referenced this issue Apr 1, 2022
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

Successfully merging a pull request may close this issue.

2 participants