Closed MarcinOrlowski closed 2 years ago
I'm sorry to hear that you're having trouble. Unfortunately, I'm not able to reproduce this problem. Can you provide a (hopefully small) example of a buildscript that fails in this way?
For reference, you can find the simple example that I tried to use to reproduce your problem on the kotlin
branch of this repo: https://github.com/kelloggm/sample-gradle-project/tree/kotlin. That repo contains a very simple Java program on which the Nullness Checker should (and, on my local box, does) issue an error. Can you have a look at the buildscript there and see if I correctly interpreted the configuration you're trying to run in?
I pushed my attempts to github so please:
git clone git@github.com:MarcinOrlowski/logisim-evolution.git
cd logisim-evolution
git checkout checkersframework-test
./gradlew build -x checkstyleMain -x checkstyleTest --stacktrace
Thanks! I believe I've found the problem. At about line 593 of your build.gradle.kts
file, it looks like you modify the options.compileArgs
property of each of your compileJava
tasks and replace it with listOf("-Xlint:deprecation", "-Xlint:unchecked")
. The issue is that in Kotlin, listOf
by default returns an immutable list. Later, when the Checker Framework plugin tries to add the extra javac arg "-AsuppressWarnings=initialization"
to that same list, the operation is rejected (because the list is immutable).
I was able to fix the issue in your build script by changing listOf
to mutableListOf
.
Because I suspect this will come up for other Kotlin users in the future, I'm going to add an exception handler to the add that'll issue a helpful warning message rather than just crashing.
> Configure project :
The Checker Framework Plugin tried to add an extraJavacArgs element to the compilerArgs for the compile task named "compileJava", but an UnsupportedOperationException was thrown. Sometimes, this is caused by using Kotlin's `listOf` method to define a set of compiler arguments; `listOf` produces an immutable list, which leads to the exception. Consider using `mutableListOf` to set compiler arguments instead.
Would you have preferred that failure mode @MarcinOrlowski? Or do you have any suggestions about the error message?
Indeed, that was the culprit. As for the error message - I cannot tell for everyone but I believe having proposed message shown instead of just face raw stacktrace would definitely be more helpful. Thanks!
In my build.gradle.kts I am trying to pass
-AsuppressWarnings=initialization
to the compiler. I addedand this works. But if I add
to the above
configure
block, then configuration step fails withjava.lang.UnsupportedOperationException
(however if list is empty, i.e.extraJavacArgs = listOf()
then this is not occuring). Output from./gradlew build --stacktrace
:What I am doing wrong?