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

Running SpotBugs on and Android project using Gradle #426

Open
baloghadamsoftware opened this issue Feb 10, 2021 · 2 comments
Open

Running SpotBugs on and Android project using Gradle #426

baloghadamsoftware opened this issue Feb 10, 2021 · 2 comments

Comments

@baloghadamsoftware
Copy link

Hello,

I am trying out SpotBugs on open-source projects. The actual goal is to test my modifications in the locally SpotBugs, but I am already stuck at running release SpotBugs.

I read several, sometimes contradiction documentations. I had various errors, none of the worked. Finally, I found this one: https://mikedemaso.com/tech/2020-06-10-spotbugs-gradle-plugin-android/

This is the only one that seemed to work, but it still does not work perfectly.

The project I am using for testing is an Android app, called microMathematics: https://github.com/mkulesh/microMathematics

I changed its build.gradle to the following three files:

gradle.zip

I also modified the Gradle version in gradle/wrapper/gradle-wrapper.properties to 5.6 because the SpotBugs Gradle plugin requires that version.

However, after the analysis I got the following error message:

Task :app:spotbugsDebug
The following classes needed for analysis were missing:
android.os.AsyncTask
android.content.ContextWrapper
android.os.Parcelable
android.os.Parcelable$Creator
android.view.View$OnLongClickListener
android.view.View$OnFocusChangeListener
android.widget.LinearLayout
android.view.View$OnClickListener
android.widget.TableLayout
android.graphics.drawable.Drawable
android.view.ScaleGestureDetector$OnScaleGestureListener
android.widget.FrameLayout
android.view.inputmethod.InputConnectionWrapper
android.text.TextWatcher
android.view.GestureDetector$SimpleOnGestureListener
android.view.ActionMode$Callback
android.app.Dialog
android.widget.ArrayAdapter
android.os.Handler
android.widget.AdapterView$OnItemClickListener
android.widget.BaseAdapter
android.view.View
android.widget.ImageView
android.widget.EditText
android.widget.TextView
android.content.ComponentCallbacks
android.view.View$OnCreateContextMenuListener
android.widget.ImageButton
android.view.ViewGroup
android.app.Activity
android.content.Context
org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlSerializer
android.content.res.Resources
android.widget.Toast
android.os.Bundle
android.widget.LinearLayout$LayoutParams
android.view.LayoutInflater
android.graphics.Paint
android.widget.RadioButton
android.widget.CheckBox
android.net.Uri
android.content.res.AssetManager
android.text.Editable
android.os.Parcel
android.content.res.TypedArray
android.graphics.Color
android.util.Log
android.graphics.Paint$Style
android.graphics.PathEffect
android.graphics.DashPathEffect
android.graphics.Typeface
android.graphics.BitmapFactory
android.graphics.Canvas
android.content.pm.PackageInfo
android.content.pm.ApplicationInfo
android.graphics.Bitmap$Config
android.graphics.Bitmap
android.graphics.Bitmap$CompressFormat
android.content.pm.PackageManager
android.content.pm.PackageManager$NameNotFoundException
android.graphics.Point
android.content.ContentResolver
android.net.Uri$Builder
android.provider.DocumentsContract
android.database.Cursor
android.content.SharedPreferences
android.content.SharedPreferences$Editor
android.graphics.Path
android.graphics.Rect
android.util.DisplayMetrics
android.view.ContextMenu
android.widget.AdapterView$AdapterContextMenuInfo
android.text.format.DateFormat
android.view.MenuItem
android.os.Message
android.text.TextPaint
android.widget.RelativeLayout$LayoutParams
android.os.Environment
android.widget.ListView
android.widget.Button
android.graphics.RectF
android.graphics.Shader
android.graphics.Shader$TileMode
android.view.View$MeasureSpec
android.graphics.LinearGradient
android.view.ViewParent
android.view.MotionEvent
android.view.ContextMenu$ContextMenuInfo
android.util.Xml
android.graphics.Matrix
android.graphics.SweepGradient
android.view.MenuInflater
android.view.Menu
android.os.IBinder
android.view.inputmethod.InputMethodManager
android.view.ActionMode
android.graphics.Paint$Cap
android.graphics.Paint$Join
android.graphics.Path$Op
android.graphics.PorterDuff$Mode
android.graphics.Xfermode
android.graphics.ColorMatrix
android.graphics.Path$FillType
android.graphics.PorterDuffXfermode
android.graphics.ColorMatrixColorFilter
android.graphics.PathMeasure
android.util.Base64
android.graphics.RadialGradient
android.widget.TextView$BufferType
android.view.Gravity
android.view.ScaleGestureDetector
android.widget.EdgeEffect
android.webkit.MimeTypeMap
android.text.TextUtils
android.view.KeyEvent
android.content.res.Configuration
android.os.LocaleList
android.widget.Scroller
android.view.FocusFinder
android.view.animation.AnimationUtils
android.graphics.Canvas$VertexMode
android.content.ClipData$Item
android.content.ClipData
android.content.ClipboardManager
android.content.res.AssetFileDescriptor
android.content.Intent
android.graphics.Picture
android.content.res.Resources$Theme
android.graphics.drawable.PictureDrawable
android.widget.RadioGroup
android.graphics.PorterDuffColorFilter
android.system.Os
android.os.Build
android.view.Window
android.view.SubMenu
android.view.ViewGroup$LayoutParams
android.util.TypedValue
android.widget.ProgressBar
android.widget.TableLayout$LayoutParams
android.widget.TableRow
android.view.WindowManager$LayoutParams
android.widget.AdapterView
android.widget.ListAdapter
android.os.Build$VERSION
android.graphics.PixelFormat
android.util.AttributeSet
android.os.Build$VERSION_CODES
android.view.ViewGroup$MarginLayoutParams
android.view.GestureDetector
android.graphics.PorterDuff
android.R$attr
android.R$color
android.R
android.R$id
android.provider.OpenableColumns
android.widget.RelativeLayout
android.provider.DocumentsContract$Document
android.Manifest$permission
android.Manifest
android.text.InputType

Task :app:spotbugsDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:spotbugsDebug'.

A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker$SpotBugsExecutor
33 SpotBugs violations were found. See the report at: file:///mnt/ssd/edmbalo/microMathematics/app/build/reports/spotbugs/debug.html

If I use the --stacktrace option, I get the following excpeption at the end:

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:spotbugsDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:166)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:163)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:156)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
    at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker$SpotBugsExecutor
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:375)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:142)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.access$000(DefaultAsyncWorkTracker.java:34)
    at org.gradle.internal.work.DefaultAsyncWorkTracker$1.run(DefaultAsyncWorkTracker.java:106)
    at org.gradle.internal.Factories$1.create(Factories.java:26)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:260)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:171)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:165)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withoutProjectLock(StopShieldingWorkerLeaseService.java:95)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:102)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:80)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:68)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:484)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:461)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:444)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:93)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:237)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:208)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:69)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:47)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:140)
    ... 34 more
    Caused by: org.gradle.api.GradleException: 33 SpotBugs violations were found. See the report at: file:///mnt/ssd/edmbalo/microMathematics/app/build/reports/spotbugs/debug.html
    at com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker$SpotBugsExecutor.execute(SpotBugsRunnerForWorker.java:115)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:47)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:46)
    at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:36)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
    at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:36)
    at org.gradle.workers.internal.IsolatedClassloaderWorker.execute(IsolatedClassloaderWorker.java:54)
    at org.gradle.workers.internal.WorkerDaemonServer.execute(WorkerDaemonServer.java:56)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:118)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)

I also tried to use newer Gradle, but then I got another kind of strange error. After that I also tried to use newer Gradle Android plugin and then this same error came back.

What I find strange is that not all, but almost all android classes are missing. Some of them are not. I grepped for all the imports and extracted a list of the used Android classes (without inner classes). I compared them to the list of missing classes and there were some differences.

imported_and_missing.zip

What did I wrong? How to analyze this project without errors? Also, how to use the locally built spotbugs instead of the one from the repository?

The Java version I use is OpenJDK 11.

On another project (https://github.com/matsim-org/matsim-libs), which uses Maven I already successfully tested my local SpotBugs instance. All I want to is to do the same on this Gradle-based project.

The third project I intend to analyze using the locally built SpotBugs is SpotBugs itself. Is there an already existing config for that?

Thank you for your help in advance!

@welcome
Copy link

welcome bot commented Feb 10, 2021

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@KengoTODA KengoTODA transferred this issue from spotbugs/spotbugs Feb 11, 2021
@KengoTODA
Copy link
Member

refs #90

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

2 participants