SlideShare a Scribd company logo
1 of 51
Download to read offline
GenevaJug
@sonarqube
@sonarlint
#sonarcloud
DIY:
Java Static Analysis
Freddy Mallet - @FreddyMallet
Ego boost
● Freddy Mallet
○ CoFounder@SonarSource
○ Father of the COBOL Code Analyzer
○ Run marathon in 4h05
○ Flat Organization Advocate
SonarLint: The Missing Piece
Fewer slides, more code!
What is Static Analysis ?
Analyzing code,
without executing it!
Detecting Code Smells,
Bugs and Vulnerabilities
A Mean to an End
20+ Languages
The Mainstream Code Analyzers
Code Analyzers at SonarSource
Back Story
Let’s Write a Code Analyzer
Lexical Analysis
Only two things are infinite, the universe and human
stupidity, and I am not sure about the former.
Lexical Analysis
Only two things are infinite, the universe and human
stupidity, and I am not sure about the former.
Albert E.definite articlesverbs
Lexical Analysis
class A {
int b;
}
Lexical Analysis
class A {
int b;
}
keywords
Identifiers
punctuators
Syntactic Analysis
Define the grammar (BNF) of your language
<class_declaration> ::= ‘class’ identifier <class_body>
<class_body> ::= ‘{‘ <field_declaration> ‘}‘
<field_declaration> ::= <type> identifier ‘;’
<type> ::= identifer
class A {
int b;
}
What’s the Purpose of a Parser ?
Grammar Tokens
Abstract Syntax Tree
The most famous parser generator is ANTLR
Abstract Syntax Tree
class_declaration
class_body
field_declaration
type
identifier:Aclass
{ }
;identifier:b
identifier:int
Syntactic Analysis
class A {
int b;
foo(int b) {
this.b = b;
}
}
Semantic Analysis
Only two things are infinite, the universe and human
stupidity, and I am not sure about the former.
Albert E.
Semantic Analysis
Only two things are infinite, the universe and human
stupidity, and I am not sure about the former.
Albert E.
Semantic Analysis
class A {
int b;
A(int b) {
this.b = b;
}
}
Java Pop Quizz
interface F1 {
}
interface F2 {
}
Java Pop Quizz
class A<T extends F1 & F2>{
void fun(F1 f1){}
void fun(T t){}
}
Java Pop Quizz
class A<T extends F2 & F1>{
void fun(F1 f1){}
void fun(T t){}
}
Java Pop Quizz
The erasure of a type
variable is the erasure of
its leftmost bound.
How Do You Know That ?
JLS is your best friend
https://docs.oracle.com/javase/specs/jls/se9/html/index.html
But Semantic Analysis Is Not Enough
Beyond Semantic: Symbolic Execution
Context-Sensitive
Path-Sensitive
Data Flow Analysis
Beyond Semantic: Symbolic Execution
Object myObject = new Object();
if(a) { myObject = null; }
...
if( !a ) { ... }
else { myObject.toString(); } //NPE
Beyond Semantic: Symbolic Execution
Object myObject = new Object();
if(a) { myObject = null; }
...
if( !a ) { … }
else { myObject.toString(); } //NPE
Program State#0
myObject != null
Beyond Semantic: Symbolic Execution
Object myObject = new Object();
if(a) { myObject = null; }
...
if( !a ) { … }
else { myObject.toString(); } //NPE
Program State#0
myObject != null
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Program State#3
...
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Program State#3
...
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Beyond Semantic: Symbolic Execution
...
if( !a ) { … }
else {
myObject.toString(); // NPE
}
Program State#1
myObject != null
a = false
Program State#2
myObject = null
a = true
Program State#4
myObject = null
a = true
Explosion of States
if(a) {...} else {...}
if(b) {...} else {...}
if(c) {...} else {...}
foo(); //evaluated 8 times
Complex Arithmetic Expressions
if(a + 1 < (b* 10 - 39) ) {
if( b > a/10 + 4 ) { … }
}
See https://fr.wikipedia.org/wiki/Satisfiability_modulo_theories
Replay The Symbolic Execution
Interprocedural Analysis
Object foo(boolean a) {
if(a) return null;
return new Object();
}
void bar() {
foo(true).toString(); // NPE
}
Method Behavior
Object foo(boolean a) {
if(a) return null;
return new Object();
}
[a -> true, return null ]
[a ->false, return !null ]
Match of Method Yield
void bar() {
foo(true).toString(); // NPE
}
[a -> true, return null ]
[a ->false, return !null ] <- Not possible
What is Static Analysis ?
Analyzing code,
without executing it.
by (symbolically) executing
all possible paths!
A New Paradigm To
Manage Code Quality
▪ Total amount of TD can be depressing
▪ How to get a budget to fix old TD?
▪ Risk of injecting functional regression
▪ This is not fun!
This is Hard
▪ Too late
▪ Pushback from teams
▪ Lack of ownership
▪ Heterogeneous requirements
▪ Quality gate
Challenges
Reimbursing the Debt
▪ No new bugs
▪ No new vulnerabilities
▪ Coverage on new code > 80%
▪ Technical Debt on new code < 5%
Changing the Game
Want to apply at SonarSource ?
Drop me an email : freddy.mallet@sonarsource.com
GenevaJug
THANKS !
@sonarqube
@sonarlint
@FreddyMallet

More Related Content

What's hot

C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
parmsidhu
 

What's hot (20)

Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5
 
Quiz test JDBC
Quiz test JDBCQuiz test JDBC
Quiz test JDBC
 
Multiple Choice Questions for Java interfaces and exception handling
Multiple Choice Questions for Java interfaces and exception handlingMultiple Choice Questions for Java interfaces and exception handling
Multiple Choice Questions for Java interfaces and exception handling
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Multiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritanceMultiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritance
 
Storage classes
Storage classesStorage classes
Storage classes
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
Storage classes
Storage classesStorage classes
Storage classes
 
Type Checking JavaScript
Type Checking JavaScriptType Checking JavaScript
Type Checking JavaScript
 
C Basics
C BasicsC Basics
C Basics
 
Java 8 - Lambdas and much more
Java 8 - Lambdas and much moreJava 8 - Lambdas and much more
Java 8 - Lambdas and much more
 
Storage classes
Storage classesStorage classes
Storage classes
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Storage classes
Storage classesStorage classes
Storage classes
 
Ch6
Ch6Ch6
Ch6
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 

Similar to Développer un moteur d'exécution symbolique en partant de rien

Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
Jens Ravens
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
techtalkdwango
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
Takuya Fujimura
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 

Similar to Développer un moteur d'exécution symbolique en partant de rien (20)

DIY: Analyse statique en Java
DIY: Analyse statique en JavaDIY: Analyse statique en Java
DIY: Analyse statique en Java
 
DRONE: A Tool to Detect and Repair Directive Defects in Java APIs Documentation
DRONE: A Tool to Detect and Repair Directive Defects in Java APIs DocumentationDRONE: A Tool to Detect and Repair Directive Defects in Java APIs Documentation
DRONE: A Tool to Detect and Repair Directive Defects in Java APIs Documentation
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
 
Beyond Ruby (RubyConf Argentina 2011)
Beyond Ruby (RubyConf Argentina 2011)Beyond Ruby (RubyConf Argentina 2011)
Beyond Ruby (RubyConf Argentina 2011)
 
Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
 
Nella mente di un alchimista
Nella mente di un alchimistaNella mente di un alchimista
Nella mente di un alchimista
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and Scala
 
Virtual Separation of Concerns
Virtual Separation of ConcernsVirtual Separation of Concerns
Virtual Separation of Concerns
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
 
Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
Parameterizing and Assembling IR-based Solutions for SE Tasks using Genetic A...
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REA
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 

More from JUG Lausanne

Reverse engineering Java et contournement du mécanisme de paiement inapp Android
Reverse engineering Java et contournement du mécanisme de paiement inapp AndroidReverse engineering Java et contournement du mécanisme de paiement inapp Android
Reverse engineering Java et contournement du mécanisme de paiement inapp Android
JUG Lausanne
 

More from JUG Lausanne (20)

Introduction aux algorithmes génétiques
Introduction aux algorithmes génétiquesIntroduction aux algorithmes génétiques
Introduction aux algorithmes génétiques
 
Reverse engineering Java et contournement du mécanisme de paiement inapp Android
Reverse engineering Java et contournement du mécanisme de paiement inapp AndroidReverse engineering Java et contournement du mécanisme de paiement inapp Android
Reverse engineering Java et contournement du mécanisme de paiement inapp Android
 
Exemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et SparkExemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et Spark
 
Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012
 
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
 
CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011
 
Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011
 
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
 
OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010
 
Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010
 
Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010
 
No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009
 
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
 
Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009
 
Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009
 
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
 
XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Développer un moteur d'exécution symbolique en partant de rien