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

PPTX
SCS DevSecOps Seminar - State of DevSecOps
PPTX
Typescript ppt
PPT
Testing concepts ppt
PPTX
Secure coding practices
PPTX
Angularjs PPT
PDF
TypeScript - An Introduction
PDF
DevSecOps: What Why and How : Blackhat 2019
PDF
DevSecOps What Why and How
SCS DevSecOps Seminar - State of DevSecOps
Typescript ppt
Testing concepts ppt
Secure coding practices
Angularjs PPT
TypeScript - An Introduction
DevSecOps: What Why and How : Blackhat 2019
DevSecOps What Why and How

What's hot (20)

PPTX
Software Testing or Quality Assurance
PPS
JUnit Presentation
ODP
Secure coding in C#
PDF
[DevSecOps Live] DevSecOps: Challenges and Opportunities
PDF
Introduction to CICD
PPTX
TypeScript Overview
PDF
Secure coding presentation Oct 3 2020
PPTX
Basic Dynamic Analysis of Malware
PDF
SAST vs. DAST: What’s the Best Method For Application Security Testing?
PDF
Practical DevSecOps Course - Part 1
PPTX
Pentesting ReST API
ODP
OWASP Secure Coding
PPTX
How To Improve Quality With Static Code Analysis
PDF
Web Application Security and Awareness
PPT
Continuous integration
PPTX
Automation - web testing with selenium
PPTX
Software testing & Quality Assurance
PPTX
DevOps introduction
PPTX
Security Testing.pptx
Software Testing or Quality Assurance
JUnit Presentation
Secure coding in C#
[DevSecOps Live] DevSecOps: Challenges and Opportunities
Introduction to CICD
TypeScript Overview
Secure coding presentation Oct 3 2020
Basic Dynamic Analysis of Malware
SAST vs. DAST: What’s the Best Method For Application Security Testing?
Practical DevSecOps Course - Part 1
Pentesting ReST API
OWASP Secure Coding
How To Improve Quality With Static Code Analysis
Web Application Security and Awareness
Continuous integration
Automation - web testing with selenium
Software testing & Quality Assurance
DevOps introduction
Security Testing.pptx
Ad

Similar to Static Code Analysis (20)

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

More from Annyce Davis (18)

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

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
L1 - Introduction to python Backend.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Introduction to Artificial Intelligence
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPT
Introduction Database Management System for Course Database
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
AI in Product Development-omnex systems
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Softaken Excel to vCard Converter Software.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
L1 - Introduction to python Backend.pptx
ai tools demonstartion for schools and inter college
PTS Company Brochure 2025 (1).pdf.......
Which alternative to Crystal Reports is best for small or large businesses.pdf
Introduction to Artificial Intelligence
How Creative Agencies Leverage Project Management Software.pdf
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Introduction Database Management System for Course Database
VVF-Customer-Presentation2025-Ver1.9.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
AI in Product Development-omnex systems

Static Code Analysis