Embedding Java Classes with code2vec: Improvements from Variable Obfuscation

04/06/2020
by   Rhys Compton, et al.
1

Automatic source code analysis in key areas of software engineering, such as code security, can benefit from Machine Learning (ML). However, many standard ML approaches require a numeric representation of data and cannot be applied directly to source code. Thus, to enable ML, we need to embed source code into numeric feature vectors while maintaining the semantics of the code as much as possible. code2vec is a recently released embedding approach that uses the proxy task of method name prediction to map Java methods to feature vectors. However, experimentation with code2vec shows that it learns to rely on variable names for prediction, causing it to be easily fooled by typos or adversarial attacks. Moreover, it is only able to embed individual Java methods and cannot embed an entire collection of methods such as those present in a typical Java class, making it difficult to perform predictions at the class level (e.g., for the identification of malicious Java classes). Both shortcomings are addressed in the research presented in this paper. We investigate the effect of obfuscating variable names during the training of a code2vec model to force it to rely on the structure of the code rather than specific names and consider a simple approach to creating class-level embeddings by aggregating sets of method embeddings. Our results, obtained on a challenging new collection of source-code classification problems, indicate that obfuscating variable names produces an embedding model that is both impervious to variable naming and more accurately reflects code semantics. The datasets, models, and code are shared for further ML research on source code.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
01/29/2021

The significance of user-defined identifiers in Java source code authorship identification

When writing source code, programmers have varying levels of freedom whe...
research
03/18/2022

Improving Semantic Consistency of Variable Names with Use-Flow Graph Analysis

Consistency is one of the keys to maintainable source code and hence a s...
research
05/30/2022

SAT-Based Extraction of Behavioural Models for Java Libraries with Collections

Behavioural models are a valuable tool for software verification, testin...
research
11/09/2020

Pointing to Subwords for Generating Function Names in Source Code

We tackle the task of automatically generating a function name from sour...
research
01/24/2022

A Two-phase Recommendation Framework for Consistent Java Method Names

In software engineering (SE) tasks, the naming approach is so important ...
research
08/29/2018

Mapping Language to Code in Programmatic Context

Source code is rarely written in isolation. It depends significantly on ...
research
12/20/2021

Vulnerability Analysis of the Android Kernel

We describe a workflow used to analyze the source code of the Android OS...

Please sign up or login with your details

Forgot password? Click here to reset