etsy / sbt-checkstyle-plugin

SBT Plugin for Running Checkstyle on Java Sources
MIT License
32 stars 25 forks source link

Checkstyle randomly exits when working on multiple projects #32

Open PenghaiZhang opened 5 years ago

PenghaiZhang commented 5 years ago

Hi,

I am using this plugin on my project which has quite a lot sub-projects. So the issue is after I type sbt checkstyle, it exits sbt in random number of sub-projects, or work very well sometimes. Working well refers to it can generate reports for all sub-projects. It seems like this plugin randomly picks up a sub-project to work and exits SBT with unknown reasons. Any ideas about how to fix it is really appreciated!

zsxwing commented 2 years ago

Hitting this issue as well. I think the root cause is noExit is not thread-safe. One thread can set the security manager back to the original one while another thread is in CheckstyleMain and calling System.exit.

Most of our projects have 0 java files. So CheckstyleMain will always fail and call System.exit for such projects. Looks like sbt-checkstyle uses NoExitSecurityManager to prevent System.exit from exiting the JVM to allow such case. But due to the above race condition, sbt-checkstyle randomly exits SBT JVM when such projects (0 java files) exist.

Our workaround is disabling parallel execution for SBT:

concurrentRestrictions in Global := {
  Tags.limitAll(1) :: Nil
}

Alternatively, you can disable checkstyle for projects that have 0 java files if your issue is the same.