Semantic Patches for Java Program Transformation (Experience Report)

Authors Hong Jin Kang, Ferdian Thung, Julia Lawall, Gilles Muller, Lingxiao Jiang, David Lo

Thumbnail PDF


  • Filesize: 0.53 MB
  • 27 pages

Document Identifiers

Author Details

Hong Jin Kang
  • School of Information Systems, Singapore Management University, Singapore
Ferdian Thung
  • School of Information Systems, Singapore Management University, Singapore
Julia Lawall
  • Sorbonne Université/Inria/LIP6, France
Gilles Muller
  • Sorbonne Université/Inria/LIP6, France
Lingxiao Jiang
  • School of Information Systems, Singapore Management University, Singapore
David Lo
  • School of Information Systems, Singapore Management University, Singapore

Cite AsGet BibTex

Hong Jin Kang, Ferdian Thung, Julia Lawall, Gilles Muller, Lingxiao Jiang, and David Lo. Semantic Patches for Java Program Transformation (Experience Report). In 33rd European Conference on Object-Oriented Programming (ECOOP 2019). Leibniz International Proceedings in Informatics (LIPIcs), Volume 134, pp. 22:1-22:27, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2019)


Developing software often requires code changes that are widespread and applied to multiple locations. There are tools for Java that allow developers to specify patterns for program matching and source-to-source transformation. However, to our knowledge, none allows for transforming code based on its control-flow context. We prototype Coccinelle4J, an extension to Coccinelle, which is a program transformation tool designed for widespread changes in C code, in order to work on Java source code. We adapt Coccinelle to be able to apply scripts written in the Semantic Patch Language (SmPL), a language provided by Coccinelle, to Java source files. As a case study, we demonstrate the utility of Coccinelle4J with the task of API migration. We show 6 semantic patches to migrate from deprecated Android API methods on several open source Android projects. We describe how SmPL can be used to express several API migrations and justify several of our design decisions.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Software notations and tools
  • Program transformation
  • Java


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Gavin M Bierman, MJ Parkinson, and AM Pitts. MJ: An imperative core calculus for Java and Java with effects. Technical report, University of Cambridge, Computer Laboratory, 2003. Google Scholar
  2. Joshua Bloch. Effective Java. Addison-Wesley Professional, 2008. Google Scholar
  3. Julien Brunel, Damien Doligez, René Rydhof Hansen, Julia L Lawall, and Gilles Muller. A foundation for flow-based program matching: Using temporal logic and model checking. In POPL, pages 114-126. ACM, 2009. Google Scholar
  4. Eric Bruneton, Romain Lenglet, and Thierry Coupaye. ASM: A code manipulation tool to implement adaptable systems. Adaptable and extensible component systems, 30(19), 2002. Google Scholar
  5. Shigeru Chiba. Javassist-a reflection-based programming wizard for Java. In Proceedings of OOPSLA'98 Workshop on Reflective Programming in C++ and Java, page 174. ACM, 1998. Google Scholar
  6. James R Cordy. The TXL source transformation language. Science of Computer Programming, 61(3):190-210, 2006. Google Scholar
  7. Barthelemy Dagenais and Martin P Robillard. SemDiff: Analysis and recommendation support for API evolution. In Proceedings of the 31st International Conference on Software Engineering, pages 599-602. IEEE Computer Society, 2009. Google Scholar
  8. Johannes Henkel and Amer Diwan. CatchUp! Capturing and replaying refactorings to support API evolution. In 27th International Conference on Software Engineering, pages 274-283. IEEE, 2005. Google Scholar
  9. Atsushi Igarashi, Benjamin C Pierce, and Philip Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM Transactions on Programming Languages and Systems (TOPLAS), 23(3):396-450, 2001. Google Scholar
  10. Paul Klint, Tijs Van Der Storm, and Jurgen Vinju. Rascal: A domain specific language for source code analysis and manipulation. In 2009 Ninth IEEE International Working Conference on Source Code Analysis and Manipulation, pages 168-177. IEEE, 2009. Google Scholar
  11. Günter Kniesel, Pascal Costanza, and Michael Austermann. JMangler-a framework for load-time transformation of Java class files. In SCAM, pages 100-110. IEEE, 2001. Google Scholar
  12. David Lacey and Oege de Moor. Imperative Program Transformation by Rewriting. In Reinhard Wilhelm, editor, Compiler Construction, pages 52-68, 2001. Google Scholar
  13. Maxime Lamothe and Weiyi Shang. Exploring the Use of Automated API Migrating Techniques in Practice: An Experience Report on Android. In 15th International Conference on Mining Software Repositories, 2018, 2018. Google Scholar
  14. Julia Lawall and Gilles Muller. Coccinelle: 10 years of automated evolution in the Linux kernel. In USENIX Annual Technical Conference, pages 601-614, 2018. Google Scholar
  15. Jun Li, Chenglong Wang, Yingfei Xiong, and Zhenjiang Hu. Swin: Towards type-safe Java program adaptation between APIs. In Proceedings of the 2015 Workshop on Partial Evaluation and Program Manipulation, pages 91-102. ACM, 2015. Google Scholar
  16. Li Li, Jun Gao, Tegawendé F Bissyandé, Lei Ma, Xin Xia, and Jacques Klein. Characterising deprecated Android APIs. In Proceedings of the 15th International Conference on Mining Software Repositories, pages 254-264. ACM, 2018. Google Scholar
  17. Tyler McDonnell, Baishakhi Ray, and Miryung Kim. An empirical study of API stability and adoption in the Android ecosystem. In Software Maintenance (ICSM), 2013 29th IEEE International Conference on, pages 70-79. IEEE, 2013. Google Scholar
  18. Sichen Meng, Xiaoyin Wang, Lu Zhang, and Hong Mei. A history-based matching approach to identification of framework evolution. In Proceedings of the 34th International Conference on Software Engineering, pages 353-363. IEEE Press, 2012. Google Scholar
  19. Gilles Muller, Yoann Padioleau, Julia L Lawall, and René Rydhof Hansen. Semantic patches considered helpful. ACM SIGOPS Operating Systems Review, 40(3):90-92, 2006. Google Scholar
  20. Beevi S Nadera, D Chitraprasad, and Vinod SS Chandra. The varying faces of a program transformation systems. ACM Inroads, 3(1):49-55, 2012. Google Scholar
  21. Hoan Anh Nguyen, Tung Thanh Nguyen, Gary Wilson Jr, Anh Tuan Nguyen, Miryung Kim, and Tien N Nguyen. A graph-based approach to API usage adaptation. In OOPSLA, pages 302-321. ACM, 2010. Google Scholar
  22. Marius Nita and David Notkin. Using twinning to adapt programs to alternative APIs. In 2010 ACM/IEEE 32nd International Conference on Software Engineering,, volume 1, pages 205-214. IEEE, 2010. Google Scholar
  23. Yoann Padioleau, Julia L. Lawall, René Rydhof Hansen, and Gilles Muller. Documenting and automating collateral evolutions in Linux device drivers. In EuroSys, pages 247-260, 2008. Google Scholar
  24. Yoann Padioleau, Julia L Lawall, and Gilles Muller. SmPL: A domain-specific language for specifying collateral evolutions in Linux device drivers. Electronic Notes in Theoretical Computer Science, 166:47-62, 2007. Google Scholar
  25. Renaud Pawlak, Martin Monperrus, Nicolas Petitprez, Carlos Noguera, and Lionel Seinturier. Spoon: A library for implementing analyses and transformations of Java source code. Software: Practice and Experience, 46(9):1155-1179, 2016. Google Scholar
  26. Luis R Rodriguez and Julia Lawall. Increasing automation in the backporting of Linux drivers using Coccinelle. In Dependable Computing Conference (EDCC), 2015 Eleventh European, pages 132-143. IEEE, 2015. Google Scholar
  27. Raja Vallée-Rai, Phong Co, Etienne Gagnon, Laurie Hendren, Patrick Lam, and Vijay Sundaresan. Soot: A Java bytecode optimization framework. In Proceedings of the 1999 Conference of the Centre for Advanced Studies on Collaborative Research (CASCON 1999), page 13, 1999. Google Scholar
  28. Eelco Visser. Stratego: A language for program transformation based on rewriting strategies system description of Stratego 0.5. In International Conference on Rewriting Techniques and Applications, pages 357-361. Springer, 2001. Google Scholar
  29. Chenglong Wang, Jiajun Jiang, Jun Li, Yingfei Xiong, Xiangyu Luo, Lu Zhang, and Zhenjiang Hu. Transforming Programs between APIs with Many-to-Many Mappings. In 30th European Conference on Object-Oriented Programming, 2016. Google Scholar
  30. Shaowei Wang, David Lo, and Xingxiao Jiang. Understanding widespread changes: A taxonomic study. In Software Maintenance and Reengineering (CSMR), 2013 17th European Conference on, pages 5-14. IEEE, 2013. Google Scholar
  31. Louis Wasserman. Scalable, example-based refactorings with Refaster. In Proceedings of the 2013 ACM Workshop on Refactoring Tools, pages 25-28. ACM, 2013. Google Scholar
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail