Detecting Inconsistent Thrown Exceptions
Lin Xu, Hao Zhong · 2021
Exception-handling is a critical mechanism in many programming languages. Although it is beneficial in many programming contexts, the bugs in this mechanism can lead to disastrous consequences. In the literature, researchers have proposed various approaches to detect the bugs in handling exceptions. Meanwhile, the thrown exceptions themselves can also be buggy, but to the best of our knowledge, no prior approach has ever been proposed to detect bugs in thrown exceptions, because it is even difficult for programmers to determine whether a thrown exception is buggy or not. In this paper, we propose the first automatic criterion (meta-oracle) to determine whether a thrown exception contains a bug. Our meta-oracle says that if the messages of two thrown exceptions are quite similar, the type of the two exceptions shall be the same. Based on this meta-oracle, we implement exMiner that is able to detect bugs in thrown exceptions. It introduces sequence mining to identify similar exception messages, and groups thrown exceptions by the patterns that are mined from their messages. From each group of exception messages, it detects the ones whose types are different as bugs in thrown exceptions. For the first time, exMiner detected three bugs from the latest versions of three Apache projects. We reported this new type of bugs to their developers, and all the bugs were confirmed and fixed.