Skip to main content

Using Machine Learning to Identify Methods Violating Immutability

  • Conference paper
  • First Online:
Intelligent Computing

Part of the book series: Lecture Notes in Networks and Systems ((LNNS,volume 284))

  • 1939 Accesses

Abstract

A characteristic example of logic errors is the problem of poorly written Java methods that render immutable objects mutable by exposing member variables. These variables can then be used to modify or delete the underlying data regardless of class invariants, leading to serious problems such as data corruption or loss. In this paper, we offer a solution for identifying such functions by implementing a machine learning-based static code analyzer. We use a Recurrent Neural Network, trained on examples that were generated with a context-free grammar, to inspect and classify Java methods that return arrays of primitive or collections of non-primitive types. Every example can be classified as “exposes class”, “does not expose class”, or, if there is insufficient information, “cannot be decided”. The trained model is capable of classifying previously unseen code snippets with good accuracy.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 169.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 219.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Barstad, V., Goodwin, M., Gjøsæter, T.: Predicting source code quality with static analysis and machine learning. In: Norsk IKT-konferanse for forskning og utdanning (2014)

    Google Scholar 

  2. Bird, S., Loper, E., Klein, E.: Natural Language Processing with Python. O’Reilly Media Inc. (2009)

    Google Scholar 

  3. Coblenz, M., Nelson, W., Aldrich, J., Myers, B., Sunshine, J.: Glacier: transitive class immutability for java. In: 2017 IEEE/ACM 39th International Conference on Software Engineering (ICSE), pp. 496–506. IEEE (2017)

    Google Scholar 

  4. Coblenz, M., Sunshine, J., Aldrich, J., Myers, B., Weber, S., Shull, F.: Exploring language support for immutability. In: 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE), pp. 736–747. IEEE (2016)

    Google Scholar 

  5. Huang, W., Milanova, A., Dietl, W., Ernst, M.D.: Reim & Reiminfer: checking and inference of reference immutability and method purity. ACM SIGPLAN Not. 47(10), 879–896 (2012)

    Article  Google Scholar 

  6. Mani, S., Sankaran, A., Aralikatte, R.: DeepTriage: exploring the effectiveness of deep learning for bug triaging. In: Proceedings of the ACM India Joint International Conference on Data Science and Management of Data, pp. 171–179 (2019)

    Google Scholar 

  7. Martin, R.C.: Clean Code: A Handbook of Agile Software Craftsmanship. Pearson Education, London (2009)

    Google Scholar 

  8. Milanova, A., Dong, Y.: Inference and checking of object immutability. In: Proceedings of the 13th International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools, pp. 1–12 (2016)

    Google Scholar 

  9. Milanova, A., Huang, W.: Dataflow and type-based formulations for reference immutability. In: International Workshop on Foundations of Object-Oriented Languages, p. 89. Citeseer (2012)

    Google Scholar 

  10. Porat, S., Biberstein, M., Koved, L., Mendelson, B.: Automatic detection of immutable fields in java. In: Proceedings of the 2000 conference of the Centre for Advanced Studies on Collaborative research, p. 10. IBM Press (2000)

    Google Scholar 

  11. Pradel, M., Sen, K.: Deep learning to find bugs. TU Darmstadt, Department of Computer Science (2017)

    Google Scholar 

  12. Schuster, M., Paliwal, K.K.: Bidirectional recurrent neural networks. IEEE Trans. Signal Process. 45(11), 2673–2681 (1997)

    Article  Google Scholar 

  13. Weber, S., Coblenz, M., Myers, B., Aldrich, J., Sunshine, J.: Empirical studies on the security and usability impact of immutability. In: 2017 IEEE Cybersecurity Development (SecDev), pp. 50–53. IEEE (2017)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2021 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Borbély, T., Wild, Á.J., Pintér, B., Gregorics, T. (2021). Using Machine Learning to Identify Methods Violating Immutability. In: Arai, K. (eds) Intelligent Computing. Lecture Notes in Networks and Systems, vol 284. Springer, Cham. https://doi.org/10.1007/978-3-030-80126-7_33

Download citation

Publish with us

Policies and ethics