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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
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)
Bird, S., Loper, E., Klein, E.: Natural Language Processing with Python. O’Reilly Media Inc. (2009)
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)
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)
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)
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)
Martin, R.C.: Clean Code: A Handbook of Agile Software Craftsmanship. Pearson Education, London (2009)
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)
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)
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)
Pradel, M., Sen, K.: Deep learning to find bugs. TU Darmstadt, Department of Computer Science (2017)
Schuster, M., Paliwal, K.K.: Bidirectional recurrent neural networks. IEEE Trans. Signal Process. 45(11), 2673–2681 (1997)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2021 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
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
DOI: https://doi.org/10.1007/978-3-030-80126-7_33
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-80125-0
Online ISBN: 978-3-030-80126-7
eBook Packages: Intelligent Technologies and RoboticsIntelligent Technologies and Robotics (R0)