Augmenting Stack Overflow with API Usage Patterns Mined from GitHub
Anastasia Reinhart1,2* Tianyi Zhang1 Mihir Marthur1 Miryung Kim1
1University of California, Los Angeles 2George Fox University
1
* Work done as a research intern at UCLA.
Augmenting Stack Overflow with API Usage Patterns Mined from GitHub - - PowerPoint PPT Presentation
Augmenting Stack Overflow with API Usage Patterns Mined from GitHub Anastasia Reinhart 1,2 * Tianyi Zhang 1 Mihir Marthur 1 Miryung Kim 1 1 University of California, Los Angeles 2 George Fox University * Work done as a research intern at UCLA. 1
Anastasia Reinhart1,2* Tianyi Zhang1 Mihir Marthur1 Miryung Kim1
1University of California, Los Angeles 2George Fox University
1
* Work done as a research intern at UCLA.
2
e.g., JDK APIs Android SDK
3
– insecure coding practices [Fischer et al., 2017] – unchecked obsolete usage [Zhou and Walker, 2016] – low readability [Treude and Robillard, 2017]
4
– insecure coding practices [Fischer et al., 2017] – unchecked obsolete usage [Zhou and Walker, 2016] – low readability [Treude and Robillard, 2017]
5
Zhang et al., Are Online Code Examples Reliable? A Study of API Misuse on Stack Overflow, ICSE 2018 Dataset: http://web.cs.ucla.edu/~tianyi.zhang/examplecheck.html
6
https://stackoverflow.com/questions/21983867
7
8
https://stackoverflow.com/questions/12100651
9
https://stackoverflow.com/questions/12100651
10
11
Stack Overflow
12
Web Browser
... <code> … </code> …
Code Extraction Pop up Generation
ExampleCheck Server API usage mining
(offline) API Misuse Detection
API misuse
13
Code Search Program Slicing Call Sequence Extraction Structured API call sequences Frequent Sequence Mining SMT-based Guard Condition Mining API usage patterns 380K Java Repositories on GitHub
1 2 3
14
Dyer et al. Boa: A language and infrastructure for analyzing ultra-large-scale software
Code Search Program Slicing Call Sequence Extraction Structured API call sequences Frequent Sequence Mining SMT-based Guard Condition Mining API usage patterns 380K Java Repositories on GitHub
1 2 3
15
Code Search Program Slicing Call Sequence Extraction Structured API call sequences Frequent Sequence Mining SMT-based Guard Condition Mining API usage patterns 380K Java Repositories on GitHub
1 2 3
16
void initInterfaceProperties(String temp, File dDir) { if(!temp.equals("props.txt")) { log.error("Wrong Template."); return; } // load default properties FileInputStream in = new FileInputStream(temp); Properties prop = new Properties(); prop.load(in); ... init properties ... // write to the property file String fPath=dDir.getAbsolutePath()+"/interface.prop"; File file = new File(fPath); if(!file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); prop.store(out, null); in.close(); }
GitHub example of File.createNewFile The focal API method
17
void initInterfaceProperties(String temp, File dDir) { if(!temp.equals("props.txt")) { log.error("Wrong Template."); return; } // load default properties FileInputStream in = new FileInputStream(temp); Properties prop = new Properties(); prop.load(in); ... init properties ... // write to the property file String fPath=dDir.getAbsolutePath()+"/interface.prop"; File file = new File(fPath); if(!file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); prop.store(out, null); in.close(); }
Data dependency up to one hop, i.e., direct dependency The focal API method
data control
18
Code Search Program Slicing Call Sequence Extraction Structured API call sequences Frequent Sequence Mining SMT-based Guard Condition Mining API usage patterns 380K Java Repositories on GitHub
1 2 3
19
new File (String); try {; new FileInputStream(File)@arg0.exists(); } catch (IOException) {; } Grammar of Structured Call Sequences
20
new File (String); try {; new FileInputStream(File)@arg0.exists(); } catch (IOException) {; } Grammar of Structured Call Sequences
21
new File (String); try {; new FileInputStream(File)@arg0.exists(); } catch (IOException) {; } Grammar of Structured Call Sequences
22
new File (String); try {; new FileInputStream(File)@arg0.exists(); } catch (IOException) {; } Grammar of Structured Call Sequences
23
Code Search Program Slicing Call Sequence Extraction Structured API call sequences Frequent Sequence Mining SMT-based Guard Condition Mining 380K Java Repositories on GitHub
1 2 3
24
Two equivalent but syntactically different guard conditions for substring(int): arg0>=0 && arg0<=rcv.length() ⇔ arg0>-1 && arg0<rcv.length()+1
25
Java Stack Overflow snippets Call Sequence Extraction Guard Condition Check Structured API call sequences Patterns API usage violations query pattern(s) Temporal Ordering Check
26
JsonObject obj = root.getAsJsonObject(); JsonElement match_number =
... System.out.println( match_number.getAsString());
SO code example [Post 29860000]
JsonObject obj = root.getAsJsonObject(); JsonElement match_number =
... System.out.println( match_number.getAsString());
27
getAsJsonObject()@true; get(String)@true; ... getAsString()@true; println(String)@true
extract SO code example [Post 29860000] Structured Call Sequence
28
extract
JsonObject obj = root.getAsJsonObject(); JsonElement match_number =
... System.out.println( match_number.getAsString());
SO code example [Post 29860000]
getAsJsonObject()@true; get(String)@true; ... getAsString()@true; println(String)@true
Structured Call Sequence
29
getAsJsonObject()@true; get(String)@true; ... getAsString()@true; println(String)@true
Structured Call Sequence
try {; getAsString()@rcv.isJsonPrimitive(); }; catch (Exception) {; };
An API Usage Pattern of JsonElement.getAsString()
30
getAsJsonObject()@true; get(String)@true; ... getAsString()@true; println(String)@true
Structured Call Sequence
try {; getAsString()@rcv.isJsonPrimitive(); }; catch (Exception) {; };
An API Usage Pattern of JsonElement.getAsString()
31
getAsJsonObject()@true; get(String)@true; ... getAsString()@true; println(String)@true
Structured Call Sequence
try {; getAsString()@rcv.isJsonPrimitive(); }; catch (Exception) {; };
An API Usage Pattern of JsonElement.getAsString()
32
33
34
Tool: https://chrome.google.com/webstore/detail/examplecheck/ amliempebckaiaklimcpopomlnklkioe Dataset: http://web.cs.ucla.edu/~tianyi.zhang/examplecheck.html
35