Using Machine Learning to Identify Methods Violating ImmutabilityOpen Website

2021 (modified: 24 Apr 2023)SAI (2) 2021Readers: Everyone
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.
0 Replies

Loading