SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
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
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
Review…
• Bug Patterns
• Not Always Right
• Use the Filters
FindBugs
2
@brwngrldev
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>
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

Weitere ähnliche Inhalte

Was ist angesagt?

Continuous integration
Continuous integrationContinuous integration
Continuous integration
amscanne
 

Was ist angesagt? (20)

Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
 
Software testing and process
Software testing and processSoftware testing and process
Software testing and process
 
PHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On LabPHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On Lab
 
Test Automation
Test AutomationTest Automation
Test Automation
 
AppSec & DevSecOps Metrics: Key Performance Indicators (KPIs) to Measure Success
AppSec & DevSecOps Metrics: Key Performance Indicators (KPIs) to Measure SuccessAppSec & DevSecOps Metrics: Key Performance Indicators (KPIs) to Measure Success
AppSec & DevSecOps Metrics: Key Performance Indicators (KPIs) to Measure Success
 
Static code analysis with sonar qube
Static code analysis with sonar qubeStatic code analysis with sonar qube
Static code analysis with sonar qube
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Presentation on Agile Testing
Presentation on Agile TestingPresentation on Agile Testing
Presentation on Agile Testing
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Malware analysis, threat intelligence and reverse engineering
Malware analysis, threat intelligence and reverse engineeringMalware analysis, threat intelligence and reverse engineering
Malware analysis, threat intelligence and reverse engineering
 
Malware Static Analysis
Malware Static AnalysisMalware Static Analysis
Malware Static Analysis
 
Security Process in DevSecOps
Security Process in DevSecOpsSecurity Process in DevSecOps
Security Process in DevSecOps
 
Jenkins
JenkinsJenkins
Jenkins
 
SOFTWARE TESTING
SOFTWARE TESTINGSOFTWARE TESTING
SOFTWARE TESTING
 
Bridging the Security Testing Gap in Your CI/CD Pipeline
Bridging the Security Testing Gap in Your CI/CD PipelineBridging the Security Testing Gap in Your CI/CD Pipeline
Bridging the Security Testing Gap in Your CI/CD Pipeline
 
DAST in CI/CD pipelines using Selenium & OWASP ZAP
DAST in CI/CD pipelines using Selenium & OWASP ZAPDAST in CI/CD pipelines using Selenium & OWASP ZAP
DAST in CI/CD pipelines using Selenium & OWASP ZAP
 
What is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | EdurekaWhat is Jenkins | Jenkins Tutorial for Beginners | Edureka
What is Jenkins | Jenkins Tutorial for Beginners | Edureka
 
Introduction to CI/CD
Introduction to CI/CDIntroduction to CI/CD
Introduction to CI/CD
 
Code Security with GitHub Advanced Security
Code Security with GitHub Advanced SecurityCode Security with GitHub Advanced Security
Code Security with GitHub Advanced Security
 

Ähnlich wie Static Code Analysis

JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
Mario Heiderich
 

Ähnlich wie Static Code Analysis (20)

Creating Gradle Plugins - Oredev
Creating Gradle Plugins - OredevCreating Gradle Plugins - Oredev
Creating Gradle Plugins - Oredev
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart Introduction
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
Pyramid of-developer-skills
Pyramid of-developer-skillsPyramid of-developer-skills
Pyramid of-developer-skills
 
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
 
Static Analysis of Mozilla Thunderbird's Code by PVS-Studio
Static Analysis of Mozilla Thunderbird's Code by PVS-StudioStatic Analysis of Mozilla Thunderbird's Code by PVS-Studio
Static Analysis of Mozilla Thunderbird's Code by PVS-Studio
 
BarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformationsBarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformations
 
BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...BDD Testing and Automating from the trenches - Presented at Into The Box June...
BDD Testing and Automating from the trenches - Presented at Into The Box June...
 
ITB2016 -BDD testing and automation from the trenches
ITB2016 -BDD testing and automation from the trenchesITB2016 -BDD testing and automation from the trenches
ITB2016 -BDD testing and automation from the trenches
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 

Mehr von Annyce Davis

Mehr von Annyce Davis (17)

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

Kürzlich hochgeladen

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 

Static Code Analysis