论文部分内容阅读
Library or framework APIs are difficult to learn and use,leading to unexpected software behaviors or bugs.Hence,various API mining techniques have been introduced to mine API usage patterns about the co-occurring of API calls or pre-conditions of API calls.However,they fail to mine patterns about an API call itself (e.g.,whether the arguments of the API call are correctly set and whether the API is suitably chosen over other similar APIs).To bridge this gap,we propose CPAM to identify change patterns (in the form of a pair of APIs before and after code changes) to fix API misuses,using historical code changes.Given a set of target APIs and a corpus of open-source projects,CPAM first selects the commits that potentially fix API misuses from the corpus,then extracts changes to API misuses in each selected commit,and finally identifies change patterns of API misuses.We implement CPAM for Java,and conduct large-scale evaluation,targeting Java SE APIs and using a corpus of 1162 Java projects.Our experimental results demonstrateCPAM's effectiveness and efficiency.By applying identified change patterns to bug detection,we find 44 new bugs,and 18 of them have been confirmed and fixed.