Mining for Boilerplate Code to Identify API Usability Problems


Designing usable APIs is cri Designing usable APIs is critical to developers’ productivity and software quality, but is quite difficult. One of the challenges is that anticipating API usability barriers and real-world usage is difficult, due to a lack of automated approaches to mine usability data at scale. In this project, we focus on one particular grievance that developers repeatedly express in online discussions about APIs: “boilerplate code.”

            static final void writeDoc(Document doc, OutputStream out) throws IOException{
  try {
    Transformer t = TransformerFactory.newInstance().newTransformer();
    t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId());
    t.transform(new DOMSource(doc), new StreamResrult(out));
  } catch(TransformerException e) {
    throw new AssertionError(e);  // Can't happen!

Java’s javax.xml.transform API is infamous for requiring a lot of boilerplate
to write an XML document to an output stream [Joshua Bloch's OOPSLA 2006 talk].

Boilerplate can occur for many reasons. For example, if the API designers didn’t anticipate some usage scenarios, the API may not directly provide some methods that programmers need, and this can lead to boilerplate. Alternatively, if the API designers opted for finer granularity operations to increase flexibility, but most clients do not use the flexibility to put things together in multiple ways, rather using the same methods in the same way, this can also lead to boilerplate. Either way, boilerplate can indicate a gap between the API designers’ intentions and real usage scenarios by clients, and is a usability issue.

Boilerplate Mining

We present MARBLE, a novel approach to automatically mine boilerplate code candidates from API client code repositories. MARBLE adapts existing techniques, including an API usage mining algorithm, an AST comparison algorithm, and a graph partitioning algorithm.

Boilerplate Candidates Found by MARBLE

We evaluate MARBLE with 13 Java APIs, and here is list of boilerplate candidates that are identified by MARBLE. MARBLE successfully identifies both already-known and new API-related boilerplate code instances.

(Click to see the candidates)
# of Boilerplate Candidates # of Candidates Labeled as Boilerplate Average Length of Candidates 12 11 5.96
android.database.sqlite 7 4 7.49 5 3 8.01
android.view.View 11 4 9.16
com.squareup.picasso 0 - -
java.beans.PropertyChangeSupport 8 3 6.04
java.beans.PropertyChangeEvent 5 0 - 3 2 3.52
java.sql.DriverManager 0 - -
javax.swing.JFrame 0 - -
javax.swing.SwingUtilities 2 1 6.64
javax.xml.parsers 3 3 11.23
javax.xml.transform 3 2 9.2


MARBLE: Mining for Boilerplate Code to Identify API Usability Problems.
[PDF] | [Slides]
Nam, D., Horvath, A., Macvean, A., Myers, B., and Vasilescu, B.
International Conference on Automated Software Engineering, ASE, IEEE (2019).


Daye Nam ( ), Amber Horvath (), Andrew Macvean (), Brad Myers ( ), and Bogdan Vasilescu ( )


This project has been funded by Google (under Faculty research awards).