Automatic Program Repair by Fixing Contracts

  • Yu Pei
  • Carlo A. Furia
  • Martin Nordio
  • Bertrand Meyer
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8411)


While most debugging techniques focus on patching implementations, there are bugs whose most appropriate corrections consist in fixing the specification to prevent invalid executions—such as to define the correct input domain of a function. In this paper, we present a fully automatic technique that fixes bugs by proposing changes to contracts (simple executable specification elements such as pre- and postconditions). The technique relies on dynamic analysis to understand the source of buggy behavior, to infer changes to the contracts that emend the bugs, and to validate the changes against general usage. We have implemented the technique in a tool called SpeciFix which works on programs written in Eiffel, and evaluated it on 44 bugs found in standard data-structure libraries. Manual analysis by human programmers found that SpeciFix suggested repairs that are deployable for 25% of the faults; in most cases, these contract repairs were preferred over fixes for the same bugs that change the implementation.


Validation Phase Generate Test Case Class Invariant Empty List Faulty Behavior 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Ammons, G., Bodík, R., Larus, J.R.: Mining specifications. In: POPL, pp. 4–16 (2002)Google Scholar
  2. 2.
    Arcuri, A.: Evolutionary repair of faulty software. Applied Soft Computing 11(4), 3494–3514 (2011)CrossRefGoogle Scholar
  3. 3.
    Ciupa, I., Pretschner, A., Oriol, M., Leitner, A., Meyer, B.: On the number and nature of faults found by random testing. Softw. Test., Verif. Reliab. 21(1), 3–28 (2011)CrossRefGoogle Scholar
  4. 4.
    Cousot, P., Halbwachs, N.: Automatic discovery of linear restraints among variables of a program. In: POPL, pp. 84–96 (1978)Google Scholar
  5. 5.
    Csallner, C., Smaragdakis, Y.: Dynamically discovering likely interface invariants. In: ICSE, pp. 861–864 (2006)Google Scholar
  6. 6.
    Dallmeier, V., Lindig, C., Wasylkowski, A., Zeller, A.: Mining object behavior with ADABU. In: WODA, pp. 17–24 (2006)Google Scholar
  7. 7.
    Dallmeier, V., Zeller, A., Meyer, B.: Generating fixes from object behavior anomalies. In: ASE, pp. 550–554. IEEE (2009)Google Scholar
  8. 8.
    Ernst, M.D., Cockrell, J., Griswold, W.G., Notkin, D.: Dynamically discovering likely program invariants to support program evolution. IEEE TSE 27(2), 99–123 (2001)Google Scholar
  9. 9.
    Ghezzi, C., Mocci, A., Monga, M.: Synthesizing intensional behavior models by graph transformation. In: ICSE, pp. 430–440 (2009)Google Scholar
  10. 10.
    Gopinath, D., Malik, M.Z., Khurshid, S.: Specification-based program repair using SAT. In: Abdulla, P.A., Leino, K.R.M. (eds.) TACAS 2011. LNCS, vol. 6605, pp. 173–188. Springer, Heidelberg (2011)CrossRefGoogle Scholar
  11. 11.
    Henkel, J., Reichenbach, C., Diwan, A.: Discovering documentation for Java container classes. IEEE TSE 33(8), 526–543 (2007)Google Scholar
  12. 12.
    Jeffrey, D., Feng, M., Gupta, N., Gupta, R.: BugFix: a learning-based tool to assist developers in fixing bugs. In: ICPC, pp. 70–79. IEEE (2009)Google Scholar
  13. 13.
    Kim, D., Nam, J., Song, J., Kim, S.: Automatic patch generation learned from human-written patches. In: ICSE, pp. 802–811. IEEE (2013)Google Scholar
  14. 14.
    Le Goues, C., Dewey-Vogt, M., Forrest, S., Weimer, W.: A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each. In: ICSE, pp. 3–13. IEEE (2012)Google Scholar
  15. 15.
    Lorenzoli, D., Mariani, L., Pezzè, M.: Automatic generation of software behavioral models. In: ICSE, pp. 501–510 (2008)Google Scholar
  16. 16.
    Nguyen, H.D.T., Qi, D., Roychoudhury, A., Chandra, S.: SemFix: program repair via semantic analysis. In: ICSE, pp. 772–781. IEEE (2013)Google Scholar
  17. 17.
    Pei, Y., Wei, Y., Furia, C.A., Nordio, M., Meyer, B.: Code-based automated program fixing. In: ASE, pp. 392–395. ACM (2011)Google Scholar
  18. 18.
    Polikarpova, N., Furia, C.A., Pei, Y., Wei, Y., Meyer, B.: What good are strong specifications? In: ICSE, pp. 257–266. ACM (2013)Google Scholar
  19. 19.
    Wei, Y., Furia, C.A., Kazmin, N., Meyer, B.: Inferring better contracts. In: ICSE, pp. 191–200. ACM (2011)Google Scholar
  20. 20.
    Wei, Y., Pei, Y., Furia, C.A., Silva, L.S., Buchholz, S., Meyer, B., Zeller, A.: Automated fixing of programs with contracts. In: ISSTA, pp. 61–72. ACM (2010)Google Scholar
  21. 21.
    Weimer, W., Nguyen, T., Le Goues, C., Forrest, S.: Automatically finding patches using genetic programming. In: ICSE, pp. 364–374. IEEE (2009)Google Scholar
  22. 22.
    Xie, T., Martin, E., Yuan, H.: Automatic extraction of abstract-object-state machines from unit-test executions. In: ICSE, pp. 835–838. IEEE (2006)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2014

Authors and Affiliations

  • Yu Pei
    • 1
  • Carlo A. Furia
    • 1
  • Martin Nordio
    • 1
  • Bertrand Meyer
    • 1
  1. 1.Chair of Software EngineeringETH ZurichSwitzerland

Personalised recommendations