SlideShare a Scribd company logo
1 of 12
Download to read offline
IMPROVING THE JAVA
TYPE SYSTEM
João Loff - 56960
Alexandre Almeida - 64712
Tiago Aguiar - 64870
BEHAVIORS
180 LOC
“CtBehavior represents a method, a constructor, or
a static constructor”
for (CtBehavior behavior : clazz.getDeclaredBehaviors()){
behavior.instrument(new ExprEditor() { ... });
if(behavior instanceof CtMethod) { ...}
if(behavior instanceof CtConstructor) { ... }
}
FIELD INITIALIZATION
We start with:
We end up with:
@Assertion("true")
int foo;
foo++;
static java.util.HashSet f$writes = new java.util.HashSet();
@Assertion("true")
int foo;
if(!f$writes.contains(foo_hash_code)) //...
foo++
f$writes.add(foo_hash_code);
if(!(true)) //...
FIELD INITIALIZATION
How to we solve this?
DOUBLE CODE INJECTION
@Assertion("true")
int foo;
@Assertion("bar>foo")
int bar;
bar=1;
foo++;
FIELD INITIALIZATION
The first injection
The second injection
if(!f$writes.contains(bar_hash_code)) //...
bar=1;
f$writes.add(bar_hash_code);
if(!(bar>foo)) //...
if(!f$writes.contains(bar_hash_code)) //...
bar=1;
f$writes.add(bar_hash_code);
if(!f$writes.contains(bar_hash_code)) //...
if(!f$writes.contains(foo_hash_code)) //...
if(!(bar>foo)) //...
f$writes.add(bar_hash_code);
if(!(bar>foo)) //...
METHOD ASSERTION
This shouldn't return NPE!
METHOD WRAPPING
Object o = new Object();
public Object getAndClear() {
return this.o = null;
}
@Assertion("getAndClear() != null")
public void m() {
this.o.toString();
}
METHOD ASSERTION
We end up with something kinda like this:
A "new" method that returns the result of the original one
public void m() {
// temp "is a" bytecode var
temp = m$wrapped();
// now we check assertions
if(!(getAndClear() != null)) //...
// and now we return!
return temp;
}
@Assertion("getAndClear() != null")
public void m$wrapped() {
this.o.toString();
}
METHOD ASSERTIONS
Inherited Method Assertions
We recursively inject code from parents assertions
class Base {
@Assertion("false")
public int fooBar(int x) { ... }
}
public class Derived extends Base {
@Override
@Assertion("true")
public int fooBar(int x) { ... }
}
public int fooBar(int x) {
temp = fooBar$wrapped(x);
if(!(false)) //...
if(!(true)) //...
return temp;
}
CONSTRUCTOR ASSERTIONS
Remember Behaviors?
That was easy.
if((behavior instanceof CtConstructor) && hasAssertion(behavior)){
CtConstructor constructor = (CtConstructor) behavior;
constructor.insertBeforeBody(
"if(!(" + getAssertionValues(constructor) + ")) //... "
);
}
ASSERTIONS ON METHOD ENTRY
We can't break original functionality!
Previous example, now with entry assertion
Object o = new Object();
public Object getAndClear() {
return this.o = null;
}
@Assertion(
value="getAndClear() != null",
entry="getAndClear() == null"
)
public void m() {
this.o.toString();
}
ASSERTIONS ON METHOD ENTRY
We inject code at begining of method and at the exit.
It should return NPE!
public void m() {
// entry assertion
if(!(getAndClear() == null)) //...
temp = m$wrapped();
// value assertion
if(!(getAndClear() != null)) //...
return temp;
}
## As you can see (getAndClear() == null) expression returned true
[java] Exception in thread "main" java.lang.NullPointerException
[java] at ist.meic.pa.tests.Base.m$wrapped(Unknown Source)
[java] at ist.meic.pa.tests.Base.m(Unknown Source)
[java] ...
[java] The assertion getAndClear() != null is false
QUESTIONS?

More Related Content

What's hot

Burrowing through go! the book
Burrowing through go! the bookBurrowing through go! the book
Burrowing through go! the bookVishal Ghadge
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Kim Hunmin
 
C++totural file
C++totural fileC++totural file
C++totural filehalaisumit
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
Advanced Patterns with io.ReadWriter
Advanced Patterns with io.ReadWriterAdvanced Patterns with io.ReadWriter
Advanced Patterns with io.ReadWriterWeaveworks
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...DevGAMM Conference
 
Standford 2015 week9
Standford 2015 week9Standford 2015 week9
Standford 2015 week9彼得潘 Pan
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3Seok-joon Yun
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphismmohamed sikander
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 

What's hot (20)

Burrowing through go! the book
Burrowing through go! the bookBurrowing through go! the book
Burrowing through go! the book
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5
 
C++totural file
C++totural fileC++totural file
C++totural file
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Advanced Patterns with io.ReadWriter
Advanced Patterns with io.ReadWriterAdvanced Patterns with io.ReadWriter
Advanced Patterns with io.ReadWriter
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Standford 2015 week9
Standford 2015 week9Standford 2015 week9
Standford 2015 week9
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
Casa
CasaCasa
Casa
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Cquestions
Cquestions Cquestions
Cquestions
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 

Viewers also liked (13)

NCOSM Sociale media in het PO
NCOSM Sociale media in het PONCOSM Sociale media in het PO
NCOSM Sociale media in het PO
 
John p
John pJohn p
John p
 
Norm iso
Norm isoNorm iso
Norm iso
 
Universidad Soñada
Universidad SoñadaUniversidad Soñada
Universidad Soñada
 
Vashishtha_ABB_2015
Vashishtha_ABB_2015Vashishtha_ABB_2015
Vashishtha_ABB_2015
 
Class4
Class4Class4
Class4
 
Tammys Genealogy Resume Final
Tammys Genealogy Resume FinalTammys Genealogy Resume Final
Tammys Genealogy Resume Final
 
Some tears are less newsworthy
Some tears are less newsworthySome tears are less newsworthy
Some tears are less newsworthy
 
устав 2013
устав 2013устав 2013
устав 2013
 
112476 oec8wo0 xva_20140328091033_65671
112476 oec8wo0 xva_20140328091033_65671112476 oec8wo0 xva_20140328091033_65671
112476 oec8wo0 xva_20140328091033_65671
 
Soluciones 2 art 9
Soluciones 2 art 9Soluciones 2 art 9
Soluciones 2 art 9
 
Conferencistas
ConferencistasConferencistas
Conferencistas
 
Wycieczka: Kraków i Sandomierz
Wycieczka: Kraków i SandomierzWycieczka: Kraków i Sandomierz
Wycieczka: Kraków i Sandomierz
 

Similar to Improving the Java Type System with Behavioral Assertions

ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdfsudhirchourasia86
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code SmellSteven Mak
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 
Transaction is a monad
Transaction is a  monadTransaction is a  monad
Transaction is a monadJarek Ratajski
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 
COScheduler In Depth
COScheduler In DepthCOScheduler In Depth
COScheduler In DepthWO Community
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptSaadAsim11
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)ThomasHorta
 

Similar to Improving the Java Type System with Behavioral Assertions (20)

Google guava
Google guavaGoogle guava
Google guava
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code Smell
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
Transaction is a monad
Transaction is a  monadTransaction is a  monad
Transaction is a monad
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
COScheduler In Depth
COScheduler In DepthCOScheduler In Depth
COScheduler In Depth
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
Property Based Testing
Property Based TestingProperty Based Testing
Property Based Testing
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
Introduccion a Jasmin
Introduccion a JasminIntroduccion a Jasmin
Introduccion a Jasmin
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Improving the Java Type System with Behavioral Assertions

  • 1. IMPROVING THE JAVA TYPE SYSTEM João Loff - 56960 Alexandre Almeida - 64712 Tiago Aguiar - 64870
  • 2. BEHAVIORS 180 LOC “CtBehavior represents a method, a constructor, or a static constructor” for (CtBehavior behavior : clazz.getDeclaredBehaviors()){ behavior.instrument(new ExprEditor() { ... }); if(behavior instanceof CtMethod) { ...} if(behavior instanceof CtConstructor) { ... } }
  • 3. FIELD INITIALIZATION We start with: We end up with: @Assertion("true") int foo; foo++; static java.util.HashSet f$writes = new java.util.HashSet(); @Assertion("true") int foo; if(!f$writes.contains(foo_hash_code)) //... foo++ f$writes.add(foo_hash_code); if(!(true)) //...
  • 4. FIELD INITIALIZATION How to we solve this? DOUBLE CODE INJECTION @Assertion("true") int foo; @Assertion("bar>foo") int bar; bar=1; foo++;
  • 5. FIELD INITIALIZATION The first injection The second injection if(!f$writes.contains(bar_hash_code)) //... bar=1; f$writes.add(bar_hash_code); if(!(bar>foo)) //... if(!f$writes.contains(bar_hash_code)) //... bar=1; f$writes.add(bar_hash_code); if(!f$writes.contains(bar_hash_code)) //... if(!f$writes.contains(foo_hash_code)) //... if(!(bar>foo)) //... f$writes.add(bar_hash_code); if(!(bar>foo)) //...
  • 6. METHOD ASSERTION This shouldn't return NPE! METHOD WRAPPING Object o = new Object(); public Object getAndClear() { return this.o = null; } @Assertion("getAndClear() != null") public void m() { this.o.toString(); }
  • 7. METHOD ASSERTION We end up with something kinda like this: A "new" method that returns the result of the original one public void m() { // temp "is a" bytecode var temp = m$wrapped(); // now we check assertions if(!(getAndClear() != null)) //... // and now we return! return temp; } @Assertion("getAndClear() != null") public void m$wrapped() { this.o.toString(); }
  • 8. METHOD ASSERTIONS Inherited Method Assertions We recursively inject code from parents assertions class Base { @Assertion("false") public int fooBar(int x) { ... } } public class Derived extends Base { @Override @Assertion("true") public int fooBar(int x) { ... } } public int fooBar(int x) { temp = fooBar$wrapped(x); if(!(false)) //... if(!(true)) //... return temp; }
  • 9. CONSTRUCTOR ASSERTIONS Remember Behaviors? That was easy. if((behavior instanceof CtConstructor) && hasAssertion(behavior)){ CtConstructor constructor = (CtConstructor) behavior; constructor.insertBeforeBody( "if(!(" + getAssertionValues(constructor) + ")) //... " ); }
  • 10. ASSERTIONS ON METHOD ENTRY We can't break original functionality! Previous example, now with entry assertion Object o = new Object(); public Object getAndClear() { return this.o = null; } @Assertion( value="getAndClear() != null", entry="getAndClear() == null" ) public void m() { this.o.toString(); }
  • 11. ASSERTIONS ON METHOD ENTRY We inject code at begining of method and at the exit. It should return NPE! public void m() { // entry assertion if(!(getAndClear() == null)) //... temp = m$wrapped(); // value assertion if(!(getAndClear() != null)) //... return temp; } ## As you can see (getAndClear() == null) expression returned true [java] Exception in thread "main" java.lang.NullPointerException [java] at ist.meic.pa.tests.Base.m$wrapped(Unknown Source) [java] at ist.meic.pa.tests.Base.m(Unknown Source) [java] ... [java] The assertion getAndClear() != null is false