SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Contract in Java
Jakub Novotn´y
January 19, 2015
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Interface
set of information published by entity (class, function, ...)
signature
contract
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Signature
everything that can be checked by compiler
method/function
name
return type
number of parameters
parameter types
thrown exceptions
synchronized, native, ...
data types
name
ancestor(s)
implemented interface
signatures of all members
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Contract
informations how to use
can not be easily checked by compiler
parameter values
returned values - for example:
o1.equals(o2) => o1.hashCode() == o2.hashCode()
equals must be reflexive, symmetric, transitive
ompareTo must be transitive, antisymmetric and should be
consistent with equals
used algorithms and methods
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
General parameters checking
always check - declared exception thrown - OK / undeclared -
fail of implementation
always publish in javadoc
use standardised methods
methods from org.springframework.util.Assert which
throws IllegalArgumentException
isTrue(boolean expression, String message)
hasLength(String text, String message)
...
assert operator for debugging
is applied with -ea switch only
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Example
1 /∗∗
2 ∗ Square root of the given number .
3 ∗
4 ∗ @param n must be >= 0
5 ∗ @return square root of {@code n}
6 ∗ @throws I l l e g a l A r g u m e n t E x c e p t i o n i f {@code n} i s < 0.
7 ∗ @see j a v a . lang . Math#s q r t
8 ∗/
9 p u b l i c double s q r t ( double n ) throws I l l e g a l A r g u m e n t E x c e p t i o n {
10 A s s e r t . i s Tr u e ( n >= 0) ;
11 return Math . s q r t ( n ) ;
12 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
Selenium IDE - Creating the test
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
IntelliJ Annotations
contract checking by annotations
internal annotations for IntelliJ IDE
Apache license
pending: include in the standard JDK
maven repository
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@Nullable
method - can return null
parameter - accepts null
variable - can hold null
producing warnings - configurable in Inspection/Probable bugs
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@Nullable - producing warning
1 public class N u l l a b l e 1 {
2 @Nullable
3 public S t r i n g a = n u l l ;
4
5 public int aLength () {
6 return a . length () ;
7 }
8 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@Nullable - producing warning
1
2 public class N u l l a b l e 2 {
3 private S t r i n g a ;
4
5 @Nullable
6 public S t r i n g getA () {
7 return a ;
8 }
9
10 public int aLength () {
11 return getA () . length () ;
12 }
13 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@NotNull
method - can not return null
parameter - does not accept null
variable - can not hold null
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@NotNull - producing error
1 public class NotNullError {
2 @NotNull
3 private S t r i n g s t r ;
4
5 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@NotNull - producing warning
1 public class NotNull1 {
2
3 private S t r i n g s t r ;
4
5 public S t r i n g t ( @NotNull S t r i n g a ) {
6 return a ;
7 }
8
9 public S t r i n g t2 ( @Nullable S t r i n g a )
{
10 return t e s t ( a ) ;
11 }
12 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@Contract
value - for constraints
pure - true = does not change the object
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
@Contract - example
1 public class Contract1 {
2
3 @Contract ( ” n u l l −> n u l l ” )
4 public S t r i n g t e s t ( S t r i n g a ) {
5 return a ;
6 }
7
8 }
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
CoFoJa
Contract For Java
contract checking by annotations
maven repository
plugin for eclipse only
Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
CoFoJa - example
1 @ In v a ri a n t ( ” s i z e () >= 0” )
2 interface Stack<T> {
3 public int s i z e () ;
4
5 @Requires ( ” s i z e () >= 1” )
6 public T peek () ;
7
8 @Requires ( ” s i z e () >= 1” )
9 @Ensures ({
10 ” s i z e () == old ( s i z e () ) − 1” ,
11 ” r e s u l t == old ( peek () ) ”
12 })
13 public T pop () ;
14
15 @Ensures ({Jakub Novotn´y Keyup
Contract in Java
Programming Against Interface Contract IntelliJ Annotations CoFoJa
That’s all folks
Jakub Novotn´y Keyup
Contract in Java

Contenu connexe

Tendances

Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteDVClub
 
Automatically Describing Program Structure and Behavior (PhD Defense)
Automatically Describing Program Structure and Behavior (PhD Defense)Automatically Describing Program Structure and Behavior (PhD Defense)
Automatically Describing Program Structure and Behavior (PhD Defense)Ray Buse
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetDevLabs Alliance
 
Going On with the Check of Geant4
Going On with the Check of Geant4Going On with the Check of Geant4
Going On with the Check of Geant4Andrey Karpov
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go projectDan Tran
 
Checking the Qt 5 Framework
Checking the Qt 5 FrameworkChecking the Qt 5 Framework
Checking the Qt 5 FrameworkAndrey Karpov
 
Where destructors meet threads
Where destructors meet threadsWhere destructors meet threads
Where destructors meet threadsShuo Chen
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP codeGabriele Santini
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?PVS-Studio
 
It's complicated, but it doesn't have to be: a Dagger journey
It's complicated, but it doesn't have to be: a Dagger journeyIt's complicated, but it doesn't have to be: a Dagger journey
It's complicated, but it doesn't have to be: a Dagger journeyThiago “Fred” Porciúncula
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and JavaCharles Anderson
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That CouldPVS-Studio
 
PLV8 - The PostgreSQL web side
PLV8 - The PostgreSQL web sidePLV8 - The PostgreSQL web side
PLV8 - The PostgreSQL web sideLucio Grenzi
 

Tendances (20)

Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
 
Automatically Describing Program Structure and Behavior (PhD Defense)
Automatically Describing Program Structure and Behavior (PhD Defense)Automatically Describing Program Structure and Behavior (PhD Defense)
Automatically Describing Program Structure and Behavior (PhD Defense)
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
 
Going On with the Check of Geant4
Going On with the Check of Geant4Going On with the Check of Geant4
Going On with the Check of Geant4
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go project
 
Checking the Qt 5 Framework
Checking the Qt 5 FrameworkChecking the Qt 5 Framework
Checking the Qt 5 Framework
 
Where destructors meet threads
Where destructors meet threadsWhere destructors meet threads
Where destructors meet threads
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?
 
C++17 now
C++17 nowC++17 now
C++17 now
 
7.Spring DI_2
7.Spring DI_27.Spring DI_2
7.Spring DI_2
 
It's complicated, but it doesn't have to be: a Dagger journey
It's complicated, but it doesn't have to be: a Dagger journeyIt's complicated, but it doesn't have to be: a Dagger journey
It's complicated, but it doesn't have to be: a Dagger journey
 
Klee introduction
Klee  introductionKlee  introduction
Klee introduction
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That Could
 
Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 
PLV8 - The PostgreSQL web side
PLV8 - The PostgreSQL web sidePLV8 - The PostgreSQL web side
PLV8 - The PostgreSQL web side
 
Deep C
Deep CDeep C
Deep C
 

Similaire à Contract in Java

iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testingsgleadow
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
React Native - Short introduction
React Native - Short introductionReact Native - Short introduction
React Native - Short introductionVisuality
 
JDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigJDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigPROIDEA
 
啄木鸟Twisted
啄木鸟Twisted啄木鸟Twisted
啄木鸟TwistedXuYj
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 FeaturesAndreas Enbohm
 
Twisted中文
Twisted中文Twisted中文
Twisted中文wsq520
 
Python and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPython and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPVS-Studio
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Murat Yener
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...PROIDEA
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseCoen De Roover
 
单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会智杰 付
 
Bootiful Reactive Testing with Mario Gray
Bootiful Reactive Testing with Mario GrayBootiful Reactive Testing with Mario Gray
Bootiful Reactive Testing with Mario GrayVMware Tanzu
 
Sony C#/.NET component set analysis
Sony C#/.NET component set analysisSony C#/.NET component set analysis
Sony C#/.NET component set analysisPVS-Studio
 

Similaire à Contract in Java (20)

iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testing
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
React Native - Short introduction
React Native - Short introductionReact Native - Short introduction
React Native - Short introduction
 
JDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigJDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk König
 
啄木鸟Twisted
啄木鸟Twisted啄木鸟Twisted
啄木鸟Twisted
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 
Android NDK Overview
Android NDK OverviewAndroid NDK Overview
Android NDK Overview
 
Twisted中文
Twisted中文Twisted中文
Twisted中文
 
Python and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPython and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error density
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
 
Enter the gradle
Enter the gradleEnter the gradle
Enter the gradle
 
Let your tests drive your code
Let your tests drive your codeLet your tests drive your code
Let your tests drive your code
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with Eclipse
 
单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会
 
Bootiful Reactive Testing with Mario Gray
Bootiful Reactive Testing with Mario GrayBootiful Reactive Testing with Mario Gray
Bootiful Reactive Testing with Mario Gray
 
Sony C#/.NET component set analysis
Sony C#/.NET component set analysisSony C#/.NET component set analysis
Sony C#/.NET component set analysis
 
Android antipatterns
Android antipatternsAndroid antipatterns
Android antipatterns
 

Plus de Keyup

Unity
UnityUnity
UnityKeyup
 
Google AdWords a Google AdSense vs. AdBlock.
Google AdWords a Google AdSense vs. AdBlock.Google AdWords a Google AdSense vs. AdBlock.
Google AdWords a Google AdSense vs. AdBlock.Keyup
 
WinJS
WinJSWinJS
WinJSKeyup
 
Redux+React
Redux+ReactRedux+React
Redux+ReactKeyup
 
Garbage Collection in Java
Garbage Collection in JavaGarbage Collection in Java
Garbage Collection in JavaKeyup
 
CSS flexbox
CSS flexboxCSS flexbox
CSS flexboxKeyup
 
Magento 2
Magento 2Magento 2
Magento 2Keyup
 
Silex
SilexSilex
SilexKeyup
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on railsKeyup
 
HHVM & Hack
HHVM & HackHHVM & Hack
HHVM & HackKeyup
 
Icinga2
Icinga2Icinga2
Icinga2Keyup
 
O auth2
O auth2O auth2
O auth2Keyup
 
Úvod do bezpečnosti na webu
Úvod do bezpečnosti na webuÚvod do bezpečnosti na webu
Úvod do bezpečnosti na webuKeyup
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptKeyup
 
Easymock
EasymockEasymock
EasymockKeyup
 
CSS 3
CSS 3CSS 3
CSS 3Keyup
 
Jenkins
JenkinsJenkins
JenkinsKeyup
 
JLint
JLintJLint
JLintKeyup
 
Angular js vs. Facebook react
Angular js vs. Facebook reactAngular js vs. Facebook react
Angular js vs. Facebook reactKeyup
 
Optimalizace rychlosti stránek
Optimalizace rychlosti stránekOptimalizace rychlosti stránek
Optimalizace rychlosti stránekKeyup
 

Plus de Keyup (20)

Unity
UnityUnity
Unity
 
Google AdWords a Google AdSense vs. AdBlock.
Google AdWords a Google AdSense vs. AdBlock.Google AdWords a Google AdSense vs. AdBlock.
Google AdWords a Google AdSense vs. AdBlock.
 
WinJS
WinJSWinJS
WinJS
 
Redux+React
Redux+ReactRedux+React
Redux+React
 
Garbage Collection in Java
Garbage Collection in JavaGarbage Collection in Java
Garbage Collection in Java
 
CSS flexbox
CSS flexboxCSS flexbox
CSS flexbox
 
Magento 2
Magento 2Magento 2
Magento 2
 
Silex
SilexSilex
Silex
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
HHVM & Hack
HHVM & HackHHVM & Hack
HHVM & Hack
 
Icinga2
Icinga2Icinga2
Icinga2
 
O auth2
O auth2O auth2
O auth2
 
Úvod do bezpečnosti na webu
Úvod do bezpečnosti na webuÚvod do bezpečnosti na webu
Úvod do bezpečnosti na webu
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Easymock
EasymockEasymock
Easymock
 
CSS 3
CSS 3CSS 3
CSS 3
 
Jenkins
JenkinsJenkins
Jenkins
 
JLint
JLintJLint
JLint
 
Angular js vs. Facebook react
Angular js vs. Facebook reactAngular js vs. Facebook react
Angular js vs. Facebook react
 
Optimalizace rychlosti stránek
Optimalizace rychlosti stránekOptimalizace rychlosti stránek
Optimalizace rychlosti stránek
 

Dernier

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Dernier (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

Contract in Java

  • 1. Programming Against Interface Contract IntelliJ Annotations CoFoJa Contract in Java Jakub Novotn´y January 19, 2015 Jakub Novotn´y Keyup Contract in Java
  • 2. Programming Against Interface Contract IntelliJ Annotations CoFoJa Interface set of information published by entity (class, function, ...) signature contract Jakub Novotn´y Keyup Contract in Java
  • 3. Programming Against Interface Contract IntelliJ Annotations CoFoJa Signature everything that can be checked by compiler method/function name return type number of parameters parameter types thrown exceptions synchronized, native, ... data types name ancestor(s) implemented interface signatures of all members Jakub Novotn´y Keyup Contract in Java
  • 4. Programming Against Interface Contract IntelliJ Annotations CoFoJa Contract informations how to use can not be easily checked by compiler parameter values returned values - for example: o1.equals(o2) => o1.hashCode() == o2.hashCode() equals must be reflexive, symmetric, transitive ompareTo must be transitive, antisymmetric and should be consistent with equals used algorithms and methods Jakub Novotn´y Keyup Contract in Java
  • 5. Programming Against Interface Contract IntelliJ Annotations CoFoJa General parameters checking always check - declared exception thrown - OK / undeclared - fail of implementation always publish in javadoc use standardised methods methods from org.springframework.util.Assert which throws IllegalArgumentException isTrue(boolean expression, String message) hasLength(String text, String message) ... assert operator for debugging is applied with -ea switch only Jakub Novotn´y Keyup Contract in Java
  • 6. Programming Against Interface Contract IntelliJ Annotations CoFoJa Example 1 /∗∗ 2 ∗ Square root of the given number . 3 ∗ 4 ∗ @param n must be >= 0 5 ∗ @return square root of {@code n} 6 ∗ @throws I l l e g a l A r g u m e n t E x c e p t i o n i f {@code n} i s < 0. 7 ∗ @see j a v a . lang . Math#s q r t 8 ∗/ 9 p u b l i c double s q r t ( double n ) throws I l l e g a l A r g u m e n t E x c e p t i o n { 10 A s s e r t . i s Tr u e ( n >= 0) ; 11 return Math . s q r t ( n ) ; 12 } Jakub Novotn´y Keyup Contract in Java
  • 7. Programming Against Interface Contract IntelliJ Annotations CoFoJa Selenium IDE - Creating the test Jakub Novotn´y Keyup Contract in Java
  • 8. Programming Against Interface Contract IntelliJ Annotations CoFoJa IntelliJ Annotations contract checking by annotations internal annotations for IntelliJ IDE Apache license pending: include in the standard JDK maven repository Jakub Novotn´y Keyup Contract in Java
  • 9. Programming Against Interface Contract IntelliJ Annotations CoFoJa @Nullable method - can return null parameter - accepts null variable - can hold null producing warnings - configurable in Inspection/Probable bugs Jakub Novotn´y Keyup Contract in Java
  • 10. Programming Against Interface Contract IntelliJ Annotations CoFoJa @Nullable - producing warning 1 public class N u l l a b l e 1 { 2 @Nullable 3 public S t r i n g a = n u l l ; 4 5 public int aLength () { 6 return a . length () ; 7 } 8 } Jakub Novotn´y Keyup Contract in Java
  • 11. Programming Against Interface Contract IntelliJ Annotations CoFoJa @Nullable - producing warning 1 2 public class N u l l a b l e 2 { 3 private S t r i n g a ; 4 5 @Nullable 6 public S t r i n g getA () { 7 return a ; 8 } 9 10 public int aLength () { 11 return getA () . length () ; 12 } 13 } Jakub Novotn´y Keyup Contract in Java
  • 12. Programming Against Interface Contract IntelliJ Annotations CoFoJa @NotNull method - can not return null parameter - does not accept null variable - can not hold null Jakub Novotn´y Keyup Contract in Java
  • 13. Programming Against Interface Contract IntelliJ Annotations CoFoJa @NotNull - producing error 1 public class NotNullError { 2 @NotNull 3 private S t r i n g s t r ; 4 5 } Jakub Novotn´y Keyup Contract in Java
  • 14. Programming Against Interface Contract IntelliJ Annotations CoFoJa @NotNull - producing warning 1 public class NotNull1 { 2 3 private S t r i n g s t r ; 4 5 public S t r i n g t ( @NotNull S t r i n g a ) { 6 return a ; 7 } 8 9 public S t r i n g t2 ( @Nullable S t r i n g a ) { 10 return t e s t ( a ) ; 11 } 12 } Jakub Novotn´y Keyup Contract in Java
  • 15. Programming Against Interface Contract IntelliJ Annotations CoFoJa @Contract value - for constraints pure - true = does not change the object Jakub Novotn´y Keyup Contract in Java
  • 16. Programming Against Interface Contract IntelliJ Annotations CoFoJa @Contract - example 1 public class Contract1 { 2 3 @Contract ( ” n u l l −> n u l l ” ) 4 public S t r i n g t e s t ( S t r i n g a ) { 5 return a ; 6 } 7 8 } Jakub Novotn´y Keyup Contract in Java
  • 17. Programming Against Interface Contract IntelliJ Annotations CoFoJa CoFoJa Contract For Java contract checking by annotations maven repository plugin for eclipse only Jakub Novotn´y Keyup Contract in Java
  • 18. Programming Against Interface Contract IntelliJ Annotations CoFoJa CoFoJa - example 1 @ In v a ri a n t ( ” s i z e () >= 0” ) 2 interface Stack<T> { 3 public int s i z e () ; 4 5 @Requires ( ” s i z e () >= 1” ) 6 public T peek () ; 7 8 @Requires ( ” s i z e () >= 1” ) 9 @Ensures ({ 10 ” s i z e () == old ( s i z e () ) − 1” , 11 ” r e s u l t == old ( peek () ) ” 12 }) 13 public T pop () ; 14 15 @Ensures ({Jakub Novotn´y Keyup Contract in Java
  • 19. Programming Against Interface Contract IntelliJ Annotations CoFoJa That’s all folks Jakub Novotn´y Keyup Contract in Java