specifying the java collections framework in javadl › ~key › keysymposium07 › slides ›...

78
Specifying the Java Collections Framework in JavaDL cand. inform. Denis Lohner Institut f¨ ur Theoretische Informatik - Universit¨ at Karlsruhe 6th KeY Symposium, 2007 Betreuer: Dipl.Inform. R. Bubel verantw. Betreuer: Prof. Dr. P. H. Schmitt

Upload: others

Post on 24-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Specifying the Java Collections Framework inJavaDL

cand. inform. Denis Lohner

Institut fur Theoretische Informatik - Universitat Karlsruhe

6th KeY Symposium, 2007

Betreuer: Dipl.Inform. R. Bubelverantw. Betreuer: Prof. Dr. P. H. Schmitt

Page 2: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 3: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 4: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 5: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 6: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 7: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 8: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Outline

1 Motivation

2 Specification by example

3 Interface specification

4 Using specifications

5 A ”new” method contract rule

6 Demo

7 Conclusion

Denis Lohner Specifying the JCF 2/20

Page 9: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Motivation

Problem

1 No sources of the JDK library available in KeY⇒ symbolical execution of library calls fail

2 For native methods sources not even exist

Why specifying the Java Collections Framework?

JCF used in many projects

Case study

Denis Lohner Specifying the JCF 3/20

Page 10: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Motivation

Problem

1 No sources of the JDK library available in KeY⇒ symbolical execution of library calls fail

2 For native methods sources not even exist

Why specifying the Java Collections Framework?

JCF used in many projects

Case study

Denis Lohner Specifying the JCF 3/20

Page 11: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Motivation

Problem

1 No sources of the JDK library available in KeY⇒ symbolical execution of library calls fail

2 For native methods sources not even exist

Why specifying the Java Collections Framework?

JCF used in many projects

Case study

Denis Lohner Specifying the JCF 3/20

Page 12: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Motivation

Problem

1 No sources of the JDK library available in KeY⇒ symbolical execution of library calls fail

2 For native methods sources not even exist

Why specifying the Java Collections Framework?

JCF used in many projects

Case study

Denis Lohner Specifying the JCF 3/20

Page 13: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Motivation

Problem

1 No sources of the JDK library available in KeY⇒ symbolical execution of library calls fail

2 For native methods sources not even exist

Why specifying the Java Collections Framework?

JCF used in many projects

Case study

Denis Lohner Specifying the JCF 3/20

Page 14: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 15: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 16: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 17: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 18: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 19: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 20: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleNormal case

Example Method

SomeLibrary.copy(java.lang.Object[] src, java.lang.Object[] dest)

Precondition

src != null & src.<created> = TRUE &

dest != null & dest.<created> = TRUE &

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

Modifies

dest[0 .. src.length]

Denis Lohner Specifying the JCF 4/20

Page 21: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 22: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 23: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 24: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 25: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 26: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

Specification by exampleExceptional case

Precondition

src.length = dest.length &

\forall int i; ( (0 <= i & i < src.length) ->

arrayStoreValid(dest, src[i]) )

Postcondition

exc = null ->

\forall int i; ( (0 <= i & i < src.length) -> dest[i] = src[i] )

&

exc != null ->

(

NullPointerException::instance(exc) = TRUE &

( src != null & dest != null ) ->

( NullPointerException::instance(exc) = FALSE ) &

NullPointerException::instance(exc) = TRUE ->

( dest = null | \forall int i; dest[i] = dest[i]@pre )

)

Denis Lohner Specifying the JCF 5/20

Page 27: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 28: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 29: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 30: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 31: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 32: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 33: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 34: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixNormal Case Exceptional Case General Concept

General Concept for specifying methods

Precondition

Nearly all the time ”true”

Postcondition

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrownThen the postcondition should look like this:

( exc = null -> φN ) &

exc != null ->

(

(W

i Exci::instance(exc) = TRUE ) &Vi( !ψExci -> Exci::instance(exc) = FALSE ) &Vi( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 6/20

Page 35: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationModel functions

Problem

Method behaviour is described by attribute changesBut:Interfaces don’t contain any attributes

Solution

Introduce some function symbols for storing necessary information(”model functions”)E.g. \nonRigid[Location] int size(java.util.List) for rememberinga Lists actual size

Denis Lohner Specifying the JCF 7/20

Page 36: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationModel functions

Problem

Method behaviour is described by attribute changesBut:Interfaces don’t contain any attributes

Solution

Introduce some function symbols for storing necessary information(”model functions”)E.g. \nonRigid[Location] int size(java.util.List) for rememberinga Lists actual size

Denis Lohner Specifying the JCF 7/20

Page 37: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationExample

Method to be specified

s = myList.size()@java.util.List;

with s @−− jint and myList @− java.util.List

Precondition

true

Postcondition

\if ( size(myList) <= java.lang.Integer.MAX VALUE)

\then (s = size(myList))

\else (s = java.lang.Integer.MAX VALUE)

Modifiess

Denis Lohner Specifying the JCF 8/20

Page 38: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationExample

Method to be specified

s = myList.size()@java.util.List;

with s @−− jint and myList @− java.util.List

Precondition

true

Postcondition

\if ( size(myList) <= java.lang.Integer.MAX VALUE)

\then (s = size(myList))

\else (s = java.lang.Integer.MAX VALUE)

Modifiess

Denis Lohner Specifying the JCF 8/20

Page 39: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationExample

Method to be specified

s = myList.size()@java.util.List;

with s @−− jint and myList @− java.util.List

Precondition

true

Postcondition

\if ( size(myList) <= java.lang.Integer.MAX VALUE)

\then (s = size(myList))

\else (s = java.lang.Integer.MAX VALUE)

Modifiess

Denis Lohner Specifying the JCF 8/20

Page 40: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationExample

Method to be specified

s = myList.size()@java.util.List;

with s @−− jint and myList @− java.util.List

Precondition

true

Postcondition

\if ( size(myList) <= java.lang.Integer.MAX VALUE)

\then (s = size(myList))

\else (s = java.lang.Integer.MAX VALUE)

Modifiess

Denis Lohner Specifying the JCF 8/20

Page 41: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 42: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 43: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 44: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 45: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 46: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixModel functions Problems

Interface specificationProblems with model functions

Introducing model methods yields to two additional problems.

1 How to initialize a model function?

Answer

Write a method contract for the <init> function of the appropriate class

2 Symbolical execution <-> use of method contracts

Solution

Never use both for the same object in one proofand assure correctness by

Proof obligation inserts new non rigid predicate

check in preconditions of contracts for it

Denis Lohner Specifying the JCF 9/20

Page 47: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationLibraries

Loading of contracts

The Library mechanism of KeY is used to load the contracts, i.e. thespecifications are stored in KeY-files

Application of Contracts

Applying contracts within a proof is done via the MethodContractRule

Denis Lohner Specifying the JCF 10/20

Page 48: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationLibraries

Loading of contracts

The Library mechanism of KeY is used to load the contracts, i.e. thespecifications are stored in KeY-files

Application of Contracts

Applying contracts within a proof is done via the MethodContractRule

Denis Lohner Specifying the JCF 10/20

Page 49: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specifications

Let S, T be types with S v TLet obj @−− S

Method call vs. method body statement

Method call

obj.m(params)

will be expanded to

Method body statement

obj.m(params)@T

where T specifies where to find the implementation of m(params)

Denis Lohner Specifying the JCF 11/20

Page 50: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specifications

Let S, T be types with S v TLet obj @−− S

Method call vs. method body statement

Method call

obj.m(params)

will be expanded to

Method body statement

obj.m(params)@T

where T specifies where to find the implementation of m(params)

Denis Lohner Specifying the JCF 11/20

Page 51: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specifications

Let S, T be types with S v TLet obj @−− S

Method call vs. method body statement

Method call

obj.m(params)

will be expanded to

Method body statement

obj.m(params)@T

where T specifies where to find the implementation of m(params)

Denis Lohner Specifying the JCF 11/20

Page 52: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsBehavioral subtyping

Let S, T be types with S v TLet obj.m(params)@T be a method body statement with obj @−− S

Which contracts are available?

Contracts written for Method m(params) in type T or a supertype

Which contracts should be available?

Contracts written for Method m(params) in type S or a supertype

Denis Lohner Specifying the JCF 12/20

Page 53: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsBehavioral subtyping

Let S, T be types with S v TLet obj.m(params)@T be a method body statement with obj @−− S

Which contracts are available?

Contracts written for Method m(params) in type T or a supertype

Which contracts should be available?

Contracts written for Method m(params) in type S or a supertype

Denis Lohner Specifying the JCF 12/20

Page 54: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsBehavioral subtyping

Let S, T be types with S v TLet obj.m(params)@T be a method body statement with obj @−− S

Which contracts are available?

Contracts written for Method m(params) in type T or a supertype

Which contracts should be available?

Contracts written for Method m(params) in type S or a supertype

Denis Lohner Specifying the JCF 12/20

Page 55: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsBehavioral subtyping

Let S, T be types with S v TLet obj.m(params)@T be a method body statement with obj @−− S

Which contracts are available?

Contracts written for Method m(params) in type T or a supertype

Which contracts should be available?

Contracts written for Method m(params) in type S or a supertype

Denis Lohner Specifying the JCF 12/20

Page 56: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsProblems

MethodContractRule available only on method body statement⇒ Possible huge proof split up (e.g. java.util.List has manysubtypes), hence same proof has to be done n times

Solution

Adapt MethodContractRule to use method call

Used specifications must be proven

Solution

Need possibility to give feedback which contracts can not be proven(native methods)

Denis Lohner Specifying the JCF 13/20

Page 57: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsProblems

MethodContractRule available only on method body statement⇒ Possible huge proof split up (e.g. java.util.List has manysubtypes), hence same proof has to be done n times

Solution

Adapt MethodContractRule to use method call

Used specifications must be proven

Solution

Need possibility to give feedback which contracts can not be proven(native methods)

Denis Lohner Specifying the JCF 13/20

Page 58: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion AppendixBehavioral subtyping Problems

Using specificationsProblems

MethodContractRule available only on method body statement⇒ Possible huge proof split up (e.g. java.util.List has manysubtypes), hence same proof has to be done n times

Solution

Adapt MethodContractRule to use method call

Used specifications must be proven

Solution

Need possibility to give feedback which contracts can not be proven(native methods)

Denis Lohner Specifying the JCF 13/20

Page 59: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Remember from creating specifications

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrown

Let Exc1 to Exck(1 ≤ k ≤ n) be caught by a program

Denis Lohner Specifying the JCF 14/20

Page 60: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Remember from creating specifications

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrown

Let Exc1 to Exck(1 ≤ k ≤ n) be caught by a program

Denis Lohner Specifying the JCF 14/20

Page 61: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Remember from creating specifications

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrown

Let Exc1 to Exck(1 ≤ k ≤ n) be caught by a program

Denis Lohner Specifying the JCF 14/20

Page 62: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Remember from creating specifications

Let φN be the postcondition for normal behaviourLet ψExci (1 ≤ i ≤ n, n ∈ N) be the condition where the exception Exci isthrownLet φExci be the postcondition that holds after Exci has been thrown

Let Exc1 to Exck(1 ≤ k ≤ n) be caught by a program

Denis Lohner Specifying the JCF 14/20

Page 63: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 64: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 65: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 66: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 67: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 68: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

A ”new” method contract rule

Then the contract that should be applied is

PreconditionVk<i≤n !ψExci

Postcondition

( exc = null -> φN ) &

exc != null ->

(

(W

1≤i≤k Exci::instance(exc) = TRUE ) &V1≤i≤k( !ψExci -> Exci::instance(exc) = FALSE ) &V1≤i≤k( Exci::instance(exc) = TRUE -> φExci )

)

Denis Lohner Specifying the JCF 15/20

Page 69: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Demo

Demo

Proving the contract of a simple methodcontainsNullElements(java.util.List)

Denis Lohner Specifying the JCF 16/20

Page 70: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Conclusion

Method contracts are capable of specifying library behaviour

For interfaces: use of model functions necessary

Need for thinking about the method contract rule

Denis Lohner Specifying the JCF 17/20

Page 71: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Conclusion

Method contracts are capable of specifying library behaviour

For interfaces: use of model functions necessary

Need for thinking about the method contract rule

Denis Lohner Specifying the JCF 17/20

Page 72: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Conclusion

Method contracts are capable of specifying library behaviour

For interfaces: use of model functions necessary

Need for thinking about the method contract rule

Denis Lohner Specifying the JCF 17/20

Page 73: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Tanks for your attention

Page 74: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Combining contracts

Assume 2 contracts given for one methodLet φ1 be the precondition of the first and φ2 the precondition of thesecondLet ψ1 be the postcondition of the first and ψ2 the postcondition of thesecondLet M1 be the modifier set of the first and M2 the modifier set of thesecond

Then a valid contract for the method is

Precondition

φ1 | φ2

Postcondition

( φ1@pre -> ψ1 ) & ( φ2@pre -> ψ2 )

Modifies

M1 ∪M2

Denis Lohner Specifying the JCF 19/20

Page 75: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Behavioral subtyping

AbstractCollection{abstract}

+remove(o)

<<interface>>Collection

+remove(o)

<<interface>>List

+remove(o)

AbstractList{abstract}

LinkedList ArrayList

implements

implements

Denis Lohner Specifying the JCF 20/20

Page 76: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Behavioral subtyping

AbstractCollection{abstract}

+remove(o)

<<interface>>Collection

+remove(o)

<<interface>>List

+remove(o)

AbstractList{abstract}

LinkedList ArrayList

implements

implements

One occurence ofObject o will removed

Denis Lohner Specifying the JCF 20/20

Page 77: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Behavioral subtyping

AbstractCollection{abstract}

+remove(o)

<<interface>>Collection

+remove(o)

<<interface>>List

+remove(o)

AbstractList{abstract}

LinkedList ArrayList

implements

implements

One occurence ofObject o will removed

First occurence ofObject o will removed

Denis Lohner Specifying the JCF 20/20

Page 78: Specifying the Java Collections Framework in JavaDL › ~key › keysymposium07 › slides › lohner-jc… · Motivation Specification Interfaces Using specs Method contract rule

Motivation Specification Interfaces Using specs Method contract rule Conclusion Appendix

Behavioral subtyping

AbstractCollection{abstract}

+remove(o)

<<interface>>Collection

+remove(o)

<<interface>>List

+remove(o)

AbstractList{abstract}

LinkedList ArrayList

implements

implements

Denis Lohner Specifying the JCF 20/20