spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
180 stars 68 forks source link

Spotbug task fails on CI with error "java.io.IOException: error=7, Argument list too long" #1162

Open parveen-bhatia opened 6 months ago

parveen-bhatia commented 6 months ago

Hi, i am using gradle plugin for the android project with below build.gradle.

plugins {
  id 'com.github.spotbugs' version '6.0.12'
  ...
}

apply plugin: "com.github.spotbugs"

spotbugs {
  toolVersion = '4.8.4'
  showStackTraces = true
  ignoreFailures = true
  useAuxclasspathFile = true
  reportsDir = file("$project.rootDir/spotbugs/reports")
  effort = Effort.MAX
  baselineFile = file("$project.rootDir/spotbugs/spotbugs_baseline.xml")
  excludeFilter = file("$project.rootDir/spotbugs/project_exclude.xml")
}

tasks.withType(SpotBugsTask) {
  group 'Verification'
  description 'Run Spotbugs on this project.'
  useAuxclasspathFile = true
  classes = files("${project.buildDir}/intermediates/javac/standardRelease")
  reports {
    xml.enabled(true)
    html.enabled(true)
  }
}

On my local with MacOS, ./gradlew spotbugsStandardRelease task works successfully and able to generate reports. However on CI (which uses linux based docker with eclipse-temurin-17), i am getting below error:

> A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForHybrid$SpotBugsExecutor
   > Process 'command '/opt/java/openjdk/bin/java'' could not be started because the command line exceed operating system limits.
* Try:
> Run with --info or --debug option to get more log output.
> Get more help at https://help.gradle.org/.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':appian-android:spotbugsStandardRelease'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:148)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
....
....
Caused by: net.rubygrapefruit.platform.NativeException: Could not start '/opt/java/openjdk/bin/java'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.startProcess(ExecHandleRunner.java:122)
    at org.gradle.process.internal.ExecHandleRunner.lambda$run$0(ExecHandleRunner.java:80)
    at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:79)
    ... 2 more
Caused by: java.io.IOException: Cannot run program "/opt/java/openjdk/bin/java" (in directory "/builds/appian/dev/android-client/appian-android"): error=7, Argument list too long
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 7 more
Caused by: java.io.IOException: error=7, Argument list too long
    ... 8 more

Following is the list of versions:

I tried enabling useAuxclasspathFile = true, which is as per https://github.com/spotbugs/spotbugs-gradle-plugin/pull/243. But still getting the issue.

KengoTODA commented 6 months ago

Could you run your build with --debug option, then it will print the argument applied to the build.

https://github.com/spotbugs/spotbugs-gradle-plugin/blob/ca33175d2644b06c43d883ede0e740d89a5caaea/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunner.kt#L106

parveen-bhatia commented 6 months ago

Thanks for the response.

I haven't provided -sourcepath value below, as this is sensitive information (LIST_NOT_PROVIDED_SENSITIVE_INFO) but -sourcepath value is around ~190605 chars Below is the snippet of some debug logs after running ./gradlew spotbugsStandardRelease --debug


2024-04-30T17:09:39.229+0000 [DEBUG] [com.github.spotbugs.snom.internal.SpotBugsRunner] Arguments for SpotBugs are generated: [-timestampNow, -auxclasspathFromFile, /builds/appian/dev/android-client/appian-android/build/spotbugs/auxclasspath/spotbugsStandardRelease, -sourcepath, {xyz.java ... (LIST_NOT_PROVIDED_SENSITIVE_INFO)}, -html=/builds/appian/dev/android-client/spotbugs/reports/standardRelease.html, -xml:withMessages=/builds/appian/dev/android-client/spotbugs/reports/standardRelease.xml, -effort:max, -visitors, SynchronizeAndNullCheckField,InitializeNonnullFieldsInConstructor,InitializeNonnullFieldsInConstructor,BooleanReturnNull,OptionalReturnNull,FinalizerNullsFields,InconsistentAnnotations,FindNullDeref,BadUseOfReturnValue, -exclude, /builds/appian/dev/android-client/spotbugs/project_exclude.xml, -excludeBugs, /builds/appian/dev/android-client/spotbugs/spotbugs_baseline.xml, -onlyAnalyze, , -projectName, appian-android (spotbugsStandardRelease), -release, 24.3, -analyzeFromFile, /builds/appian/dev/android-client/appian-android/build/spotbugsStandardRelease-analyse-class-file.txt, -nested:false]
2024-04-30T17:09:39.233+0000 [DEBUG] [com.github.spotbugs.snom.internal.SpotBugsRunner] Arguments for JVM process are generated: [-XX:MaxHeapSize=1g]
....
....
....

2024-04-30T17:09:41.062+0000 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Execution worker: released lock on worker lease
2024-04-30T17:09:41.070+0000 [INFO] [com.github.spotbugs.snom.internal.SpotBugsRunnerForHybrid$SpotBugsExecutor$Inject] Spotbugs will be executed using Java Toolchain configuration: /opt/java/openjdk/bin/java
2024-04-30T17:09:41.079+0000 [INFO] [org.gradle.process.internal.JavaExecHandleBuilder] Shortening Java classpath [xyz.jar ...] with /home/appian/.gradle/.tmp/gradle-javaexec-classpath3822330201620710010.jar
2024-04-30T17:09:41.080+0000 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'command '/opt/java/openjdk/bin/java''. Working directory: /builds/appian/dev/android-client/appian-android Command: /opt/java/openjdk/bin/java -XX:MaxHeapSize=1g -Xmx1g -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /home/appian/.gradle/.tmp/gradle-javaexec-classpath3822330201620710010.jar edu.umd.cs.findbugs.FindBugs2 -exitcode -timestampNow -auxclasspathFromFile /builds/appian/dev/android-client/appian-android/build/spotbugs/auxclasspath/spotbugsStandardRelease -sourcepath {xyz.java ... (LIST_NOT_PROVIDED_SENSITIVE_INFO)} -html=/builds/appian/dev/android-client/spotbugs/reports/standardRelease.html -xml:withMessages=/builds/appian/dev/android-client/spotbugs/reports/standardRelease.xml -effort:max -visitors SynchronizeAndNullCheckField,InitializeNonnullFieldsInConstructor,InitializeNonnullFieldsInConstructor,BooleanReturnNull,OptionalReturnNull,FinalizerNullsFields,InconsistentAnnotations,FindNullDeref,BadUseOfReturnValue -exclude /builds/appian/dev/android-client/spotbugs/project_exclude.xml -excludeBugs /builds/appian/dev/android-client/spotbugs/spotbugs_baseline.xml -onlyAnalyze  -projectName appian-android (spotbugsStandardRelease) -release 24.3 -analyzeFromFile /builds/appian/dev/android-client/appian-android/build/spotbugsStandardRelease-analyse-class-file.txt -nested:false
2024-04-30T17:09:41.085+0000 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
2024-04-30T17:09:41.085+0000 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command '/opt/java/openjdk/bin/java'.
2024-04-30T17:09:41.093+0000 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
2024-04-30T17:09:41.093+0000 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/opt/java/openjdk/bin/java'' finished with exit value -1 (state: FAILED)```
parveen-bhatia commented 6 months ago

Hi @KengoTODA or @rpalcolea any idea what can be wrong or anything else i can try. Please let me know if any more information is required.

KengoTODA commented 6 months ago

Currently SpotBugs has no sourcepathFromFile or similar solution, so what I can suggest is just to shorten the sourcepath.

kavinarasu commented 6 months ago

I filed a similar issue https://github.com/spotbugs/spotbugs-gradle-plugin/issues/1176. Shortening the sourcepath will be difficult for my project. Any other suggestions? Is it possible to build sourcepathFromFile solution?