Automatic detection of immutable fields in Java

  • Authors:
  • Sara Porat;Marina Biberstein;Larry Koved;Bilha Mendelson

  • Affiliations:
  • IBM Research Laboratory in Haifa, Israel;IBM Research Laboratory in Haifa, Israel;IBM T. J. Watson Research Center, NY;IBM T. J. Watson Research Center, NY

  • Venue:
  • CASCON '00 Proceedings of the 2000 conference of the Centre for Advanced Studies on Collaborative research
  • Year:
  • 2000

Quantified Score

Hi-index 0.00

Visualization

Abstract

This paper introduces techniques to detect mutability of fields and classes in Java. A variable is considered to be mutable if a new value is stored into it, as well as if any of its reachable variables is mutable. We present a static flow-sensitive analysis algorithm which can be applied to any Java component. The analysis classifies fields and classes as either mutable or immutable. In order to facilitate openworld analysis, the algorithm identifies situations that expose variables to potential modification by code outside the component, as well as situations where variables are modified by the analyzed code. We also present an implementation of the analysis which focuses on detecting mutability of class variables, so as to avoid isolation problems. The implementation incorporates intra- and inter-procedural data-flow analyses and is shown to be highly scalable. Experimental results demonstrate the effectiveness of the algorithms.