SlideShare a Scribd company logo
Static Code Analysis
Static Code Analysis
@brwngrldev
+AnnyceDavis
“I’ll be learning
something new
on my deathbed.”
Checking your program for errors
without executing it
What is it?
@brwngrldev
Testing
What it’s not
@brwngrldev
1 / 7 - 10
@brwngrldev
Static Code Analysis
1 / 10
@brwngrldev
1000
The tools…
Checkstyle
1
FindBugs
2
PMD
3
Lint
4
@brwngrldev
@brwngrldev
Lint
Checkstyle
FindBugs
PMD
Checkstyle
“… a development tool to help
programmers write Java code that
adheres to a coding standard.”
Source
Files
config.xml
Checkstyle Tool
Modules
Design
Formatting
Code Complexity
apply plugin: ‘checkstyle’
task checkstyle(type: Checkstyle) {

description 'Checks if the code passes quality standards'

group 'verification'



configFile file(‘checkstyle.xml')
…

}
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max" value=“120"/>
</module>



<module name=“CyclomaticComplexity">
<property name="max" value=“8"/>
</module>
…
playerControlConfig.setShowClosedCaptionsButton(a.getBo


<module name=“CyclomaticComplexity">
<property name="max" value=“8"/>
</module>
Example
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
switch (video.getCategory()) {
case "CAT1" :
playVideo(video);
if (video.getLargeImageUrl() == null) {
video.setLargeImageUrl("http://www.largeImage.png");
}
updateMetadata(video);
break;
case "CAT2" :
if (video.getLargeImageUrl() == null) {
video.setLargeImageUrl("http://www.smallImage.png");
… warning: Cyclomatic Complexity is 9
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
updateVideoBasedOnCategory(video);
}
}
private void updateVideoBasedOnCategory(Video video) {
switch (video.getCategory()) {
case "CAT1" :
playVideo(video);
if (video.getLargeImageUrl() == null) {
video.setLargeImageUrl("http://www.largeImage.png");
}
updateMetadata(video);
break;
7
switch (video.getCategory()) {
case "CAT1" :
playVideo(video);
updateMetaDataAndUrl(video, "http://www.largeImage.png");
break;
…
4
@brwngrldev
Review…
• Formatting
• Code Complexity
• Refactor Gradually
@brwngrldev
Checkstyle
1
FindBugs
But this…
“…inspect Java bytecode
for occurrences of bug
patterns”
apply plugin: ‘findbugs’
task findbugs(type: FindBugs) {
description 'Run findbugs'
group 'verification'
effort 'max'
excludeFilter file('findbugs-exclude.xml')
…

}
<FindBugsFilter>

<Match>

<Class name="~.*R$.*"/>

</Match>
<Match>

<Bug pattern="HE_EQUALS_NO_HASHCODE"/>

</Match>
…

</FindBugsFilter>
Example
gradle findbugs
Static Code Analysis
Static Code Analysis
Review…
• Bug Patterns
• Not Always Right
• Use the Filters
FindBugs
2
@brwngrldev
Static Code Analysis
PMD
“…finds common programming flaws like
unused variables, empty catch blocks…”
apply plugin: ‘pmd’
task pmd(type: Pmd) {
description 'Run pmd'
group 'verification'
ruleSetFiles = files("./qa-checks/pmd-ruleset.xml")
…

}
<ruleset>

<rule ref="rulesets/java/braces.xml" />

<rule ref="rulesets/java/strings.xml" />

<rule ref="rulesets/java/basic.xml" />
…

</ruleset>
Braces Ruleset
Example
gradle pmd
Find out why
Fix it…
Review…
• Possible Bugs
• Wasteful Usage
• Duplicate Code
@brwngrldev
PMD
3
Ewww!!!
“…checks for structural code problems that
could affect the quality and performance of
your application.”
Lint
Lintian
JSLintAndroid Lint Splint
PC-Lint
PyLint
cpplint
Example
Android Lint
<lint>

<issue id="IconColors" severity="ignore" />


<issue id="IconMissingDensityFolder" severity="ignore" />


<issue id="UnusedResources">

<ignore path="**/config.xml" />

</issue>
…

</lint>
Static Code Analysis
Static Code Analysis
Continous Integration
Review
• Structural Issues
• Exclude Checks
• Continuous Integration
Lint
4
@brwngrldev
Summary
PMD
Checkstyle
FindBugs
Lint
@brwngrldev
Resources
• Clean Code - http://amzn.to/1DJybxH
• Effective Java - http://amzn.to/1Ku8Xel
• Google Code Style - http://goo.gl/8Pf6J3
• QA Checks - http://git.io/vCMwc
• Conquering Cyclomatic Complexity - http://goo.gl/lRoPXN
• Using Android Lint - http://goo.gl/Zl2BPx
• Static Code Analysis Tools - https://goo.gl/0Hczxn
@brwngrldev
Photo Credits
• Slide 7 - https://www.flickr.com/photos/orinrobertjohn/13068719
• Slide 20 - https://www.flickr.com/photos/oakleyoriginals/2750185692
• Slide 41 - https://commons.wikimedia.org/wiki/File:Navel_lint_ball.jpg
• Slide 50 - https://pixabay.com/en/thumb-success-successful-fan-
faust-328420/
@brwngrldev
Thanks!
@brwngrldev
+AnnyceDavis
www.adavis.info

More Related Content

What's hot (20)

PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PPT
Test Automation Framework Designs
Sauce Labs
 
PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PPTX
SQLite - Overview
Emanuele Bartolesi
 
PPTX
Typescript ppt
akhilsreyas
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PDF
Teste de performance com JMeter: como criar e executar os testes em aplicaçõe...
Edlaine Zamora
 
PDF
소프트웨어 테스팅
영기 김
 
PPTX
Software testing
balamurugan.k Kalibalamurugan
 
PPS
JUnit Presentation
priya_trivedi
 
PPT
Tecnicas Para Planejamento E Execucao De Testes De Software
marthahuback
 
PDF
Modern Python Testing
Alexander Loechel
 
PPT
Software Testing 101
QA Hannah
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PPTX
Introduction to software testing
Hadi Fadlallah
 
PDF
Automation Testing using Selenium
Naresh Chintalcheru
 
PPTX
Unit tests & TDD
Dror Helper
 
PDF
테스터가 말하는 테스트코드 작성 팁과 사례
SangIn Choung
 
DOCX
Code review guidelines
Lalit Kale
 
PPTX
Code Review
Mikalai Alimenkou
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Test Automation Framework Designs
Sauce Labs
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
SQLite - Overview
Emanuele Bartolesi
 
Typescript ppt
akhilsreyas
 
Test Automation and Selenium
Karapet Sarkisyan
 
Teste de performance com JMeter: como criar e executar os testes em aplicaçõe...
Edlaine Zamora
 
소프트웨어 테스팅
영기 김
 
JUnit Presentation
priya_trivedi
 
Tecnicas Para Planejamento E Execucao De Testes De Software
marthahuback
 
Modern Python Testing
Alexander Loechel
 
Software Testing 101
QA Hannah
 
Unit Testing Concepts and Best Practices
Derek Smith
 
Introduction to software testing
Hadi Fadlallah
 
Automation Testing using Selenium
Naresh Chintalcheru
 
Unit tests & TDD
Dror Helper
 
테스터가 말하는 테스트코드 작성 팁과 사례
SangIn Choung
 
Code review guidelines
Lalit Kale
 
Code Review
Mikalai Alimenkou
 

Similar to Static Code Analysis (20)

PDF
Infinum Android Talks #14 - How (not) to get f***** by checkstyle, pdm, findb...
Infinum
 
PDF
Achieving quality with tools case study
EosSoftware
 
PPT
Static Analysis
alice yang
 
PPTX
Java Code Quality Tools
Orest Ivasiv
 
PPTX
Static code analysis: what? how? why?
Andrey Karpov
 
PPTX
FaultHunter workshop (SourceMeter for SonarQube plugin module)
FrontEndART
 
PPSX
Coding standard
FAROOK Samath
 
PPTX
Does static analysis need machine learning?
Andrey Karpov
 
PDF
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Ganesh Samarthyam
 
PPTX
Static analysis: Around Java in 60 minutes
Andrey Karpov
 
PDF
Code analyzer: FindBugs and PMD
Kan-Han (John) Lu
 
PPT
Introduction to automated quality assurance
Philip Johnson
 
PDF
Jdj Foss Java Tools
Ganesh Samarthyam
 
PDF
Mining Fix Patterns for FindBugs Violations
Dongsun Kim
 
PDF
Infinum Android Talks #04 - Android Lint
Denis_infinum
 
PDF
Infinum Android Talks #04 - Android Lint
Infinum
 
PPTX
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Andrey Karpov
 
PPTX
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
Andrey Karpov
 
PPTX
PVS-Studio and static code analysis technique
Andrey Karpov
 
PDF
Machine Learning in Static Analysis of Program Source Code
Andrey Karpov
 
Infinum Android Talks #14 - How (not) to get f***** by checkstyle, pdm, findb...
Infinum
 
Achieving quality with tools case study
EosSoftware
 
Static Analysis
alice yang
 
Java Code Quality Tools
Orest Ivasiv
 
Static code analysis: what? how? why?
Andrey Karpov
 
FaultHunter workshop (SourceMeter for SonarQube plugin module)
FrontEndART
 
Coding standard
FAROOK Samath
 
Does static analysis need machine learning?
Andrey Karpov
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Ganesh Samarthyam
 
Static analysis: Around Java in 60 minutes
Andrey Karpov
 
Code analyzer: FindBugs and PMD
Kan-Han (John) Lu
 
Introduction to automated quality assurance
Philip Johnson
 
Jdj Foss Java Tools
Ganesh Samarthyam
 
Mining Fix Patterns for FindBugs Violations
Dongsun Kim
 
Infinum Android Talks #04 - Android Lint
Denis_infinum
 
Infinum Android Talks #04 - Android Lint
Infinum
 
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Andrey Karpov
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
Andrey Karpov
 
PVS-Studio and static code analysis technique
Andrey Karpov
 
Machine Learning in Static Analysis of Program Source Code
Andrey Karpov
 
Ad

More from Annyce Davis (18)

PDF
Getting a Grip on GraphQL
Annyce Davis
 
PDF
RxJava In Baby Steps
Annyce Davis
 
PDF
No internet? No Problem!
Annyce Davis
 
PDF
First Do No Harm - 360|AnDev
Annyce Davis
 
PDF
First Do No Harm - Droidcon Boston
Annyce Davis
 
PDF
Creating Gradle Plugins - Oredev
Annyce Davis
 
PDF
Developing Apps for Emerging Markets
Annyce Davis
 
PDF
Develop Maintainable Apps - edUiConf
Annyce Davis
 
PDF
Creating Gradle Plugins - GR8Conf US
Annyce Davis
 
PDF
From Grails to Android: A Simple Journey
Annyce Davis
 
PDF
Google I/O 2016 Recap
Annyce Davis
 
PDF
Say It With Video
Annyce Davis
 
PDF
Screen Robots: UI Tests in Espresso
Annyce Davis
 
PDF
Creating Gradle Plugins
Annyce Davis
 
PDF
Develop Maintainable Apps
Annyce Davis
 
PDF
Android Testing, Why So Hard?!
Annyce Davis
 
PDF
Measuring Audience Engagement through Analytics
Annyce Davis
 
PDF
DC Media Innovations Kick-Off Meetup
Annyce Davis
 
Getting a Grip on GraphQL
Annyce Davis
 
RxJava In Baby Steps
Annyce Davis
 
No internet? No Problem!
Annyce Davis
 
First Do No Harm - 360|AnDev
Annyce Davis
 
First Do No Harm - Droidcon Boston
Annyce Davis
 
Creating Gradle Plugins - Oredev
Annyce Davis
 
Developing Apps for Emerging Markets
Annyce Davis
 
Develop Maintainable Apps - edUiConf
Annyce Davis
 
Creating Gradle Plugins - GR8Conf US
Annyce Davis
 
From Grails to Android: A Simple Journey
Annyce Davis
 
Google I/O 2016 Recap
Annyce Davis
 
Say It With Video
Annyce Davis
 
Screen Robots: UI Tests in Espresso
Annyce Davis
 
Creating Gradle Plugins
Annyce Davis
 
Develop Maintainable Apps
Annyce Davis
 
Android Testing, Why So Hard?!
Annyce Davis
 
Measuring Audience Engagement through Analytics
Annyce Davis
 
DC Media Innovations Kick-Off Meetup
Annyce Davis
 
Ad

Recently uploaded (20)

PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 

Static Code Analysis