Você está na página 1de 21

Introduo

Motivao: Segundo a ES (falhas e


recuperao)
Abordagens e limitaes
Soluo proposta
Contribuio da soluo


-Design By Contract-Java
Jass
iContract / jContract
DBCProxy framework
JML


Outras ferramentas
ESC/java
LOOP
jmlunit
Assertivas em jass
Preconditions and postconditions: 'require'
and 'ensure;
The classinvariant: 'invariant;
The loopinvariant and the loop variant:
'invariant' and 'variant;
The check-statement: 'check;
The rescue-block: 'rescue' and the retry-
statement: 'retry;

kind of assertion type of
expressions
usage of fields
and methods
usage of local
variables
usage of
formal
parameters
usage of Old
and Result
precondition
boolean special not allowed allowed not allowed
postcondition
boolean allowed not allowed allowed allowed
class invariant
boolean allowed not allowed not allowed not allowed
loop invariant
boolean allowed allowed allowed not allowed
loop variant
int allowed allowed allowed not allowed
check
boolean allowed allowed allowed not allowed
Precondition

public void addElement (Object o) {
/** require !isFull(); o != null; **/
...
}
Postcondition
public void addElement (Object o) {
...
/** ensure !isEmpty() && contains(o); **/
}
Old:
public void addElement (Object o) {
...
/** ensure !isEmpty() && contains(o); Old.count == count-1; **/
}

Changeonly:

public void addElement (Object o) {
...
/** ensure !isEmpty() && contains(o);
Old.count == count-1;
changeonly{count,buffer}; **/

}

O estado do objeto no incio do
mtodo armazenado na varivel
especial old
A palavra changeonly seguida por uma
lista de atributos. Se essa lista
especificada em uma ps-condio
apenas os atributos declarados podem
alterar seus valores.
Class invariant
public class Buffer {
...
/** invariant 0 <= in - out && in - out <= buffer.length; **/
}
O invariante da classe
verificada sempre que um
mtodo da classe chamado ou
encerrado.
Loop invariant and variant

public boolean contains(Object o) {
/** require o != null; **/
for (int i = 0; i < buffer.length; i++)
/** invariant 0 <= i && i <= buffer.length; **/
/** variant buffer.length - i **/
if (buffer[i].equals(o)) return true;
return false;
/** ensure changeonly{}; **/
}
check
x = y / z;
/** check z!=0; **/
/** check x >= 0; **/
rescue-block
public void add(Object o) {
/** require [valid_object] o != null;
[buffer_not_full] !full(); **/ ...
/** ensure ... **/
/** rescue catch (PreconditionException e) {
if (e.label.equals("valid_object")) {
o = new DefaultObject(); retry;}
else throw e;
}
}
retry-statement

Como as assertivas so checadas
Exception Is thrown when ...
PreconditionException ... the precondition of a method does not hold.
PostconditionException ... the postcondition of a method does not hold.
InvariantException ... the invariant of a class does not hold.
LoopInvariantException ... the loop invariant for a certain loop iteration does not hold.
LoopVariantException ... the loop variant is not decreased or out of its bounds.
CheckException ... the assertion of a check statement does not hold.
RefinementException ... the class signals a refinement but does not match the refinement
requirements.
Trace-Assertions
estabelece a ordem de invocaes de mtodos
vlidos;
init().b -> init().e -> start().b -> start().e.
mtodo start () s poder ser invocada depois
de init () terminar a sua execuo
JML
O uso bsico de JML especificar
formalmente o comportamento dos mdulos
(classes e interfaces) de programas Java.
A Runtime Assertion Checker for the
Java Modeling Language (JML)


Referncias
iContract: http://www.javaworld.com/article/2074956/learn-
java/icontract--design-by-contract-in-java.html
jContract: http://jcontractor.sourceforge.net/
DbcProxy: http://www.javaworld.com/article/2074026/testing-
debugging/implement-design-by-contract-for-java-using-dynamic-
proxies.html
Jass: http://csd.informatik.uni-oldenburg.de/~jass/index.html
JML: (provissorio)
http://javafree.uol.com.br/topic-859486-JML-Java-Modeling-Language.html

Coisas que tenho que estudar
apesctJ
Anotation
Exception java
Programao modular
Tratamento de erros na nvel de aplicaes
API Refletion do JAVA
Generics / Debug
Avaliar na Semana
Artigos sobre Falhas
Artigos sobre recuperao de falhas
Abordagens dos artigos
Limitaes das abordagens
Trabalhos Futuros
http://www.journaldev.com/721/java-annotations-tutorial-
with-custom-annotation-example-and-parsing-using-
reflection
http://docs.oracle.com/javase/tutorial/java/annotations/pr
edefined.html
http://www.mkyong.com/java/java-custom-annotations-
example/

Você também pode gostar