TL;DR
This paper introduces JC-Finder, a novel tool for detecting third-party library (TPL) reuse in Java projects through code cloning. It addresses limitations of existing methods by focusing on class-level analysis and preserving inter-function relationships, achieving higher accuracy and efficiency than prior approaches.
What Problem Does This Paper Address?
Software development heavily relies on third-party libraries (TPLs), which speeds up development but introduces challenges in management and potential ethical issues like license violations and code plagiarism. Existing Software Composition Analysis (SCA) tools primarily use two methods: package-manager-based (PM-based) SCA, which tracks declared dependencies, and clone-based SCA, which detects copied code. While code cloning is a common way TPLs are introduced in Java, existing clone-based SCA tools are not specifically designed for Java's object-oriented nature. They often overlook crucial aspects like class-level reuse and the intricate relationships between functions (e.g., polymorphism, inheritance), leading to incomplete or inaccurate TPL detection. Furthermore, some tools can be bogged down by trivial code, increasing false positives.
Methods
JC-Finder tackles these issues with a novel approach centered on class-level tree analysis. The core methodology involves three main stages:
- Feature Extracting: This stage involves parsing Java source code, grouping functions by class, and generating Abstract Syntax Trees (ASTs) for each function. Crucially, it preserves inter-function relationships by linking function ASTs within a class based on invocations, creating a "Linked Function AST." These are then aggregated into a "Class AST," whose hash value represents the class's features.
- Feature Refining: To improve efficiency and accuracy, JC-Finder applies several filtering steps:
- Filter Supporting Classes: Removes interfaces, empty classes, classes with only trivial functions, structural classes from design patterns, and test classes.
- Filter Classes By Centrality: Uses PageRank to identify and retain classes that are central to a library's functionality, discarding less important ones.
- Filter Classes By Clone: Addresses the issue of multiple TPLs containing the same class by using timestamps to identify the original class and remove duplicates.
- TPL Recognition: The refined class features are then compared against a reference dataset of TPLs. Matched features serve as evidence of TPL reuse, and if multiple pieces of evidence point to a specific TPL, it's flagged as reused.
A key innovation is the focus on class-level granularity, which balances the detail of function-level analysis with the broader context of file-level analysis, better capturing Java's OOP structure.
Datasets
- Reference Dataset: A collection of 9,965 popular Maven libraries, comprising 543,286 historical versions. This dataset is used to extract features of known TPLs.
- Test Dataset: 7,974 real-world Java projects from GitHub, filtered for quality and buildability. This dataset is used to test JC-Finder's ability to detect TPL reuse in actual projects.
- Test Data with Ground Truth: A subset of 1,000 projects from the Test Dataset, for which manual ground truth labeling was performed by experts to validate TPL reuse. This dataset is crucial for evaluating the accuracy of JC-Finder and other tools.
Key Insights and Ideas
- Class-level is the sweet spot for Java TPL detection: File-level analysis is too coarse, and while function-level can find more clones, it misses crucial inter-function relationships vital for understanding Java's OOP nature. Class-level analysis strikes a better balance.
- Inter-function relationships are key: The paper highlights that functions within a class are often cloned together with their callees (associated clones) or in groups that suggest shared functionality (conjugate clones). Ignoring these relationships leads to incomplete TPL detection.
- Trivial functions are a major source of noise: Getters, setters, and other simple utility functions can inflate clone detection results, leading to false positives. JC-Finder's filtering mechanisms are essential for mitigating this.
- Code cloning is a significant, often undeclared, source of TPL reuse: A substantial portion of TPLs are introduced via code cloning rather than explicit package manager declarations, meaning PM-based SCA alone misses a significant amount of reuse.
Key Results
- High Accuracy: JC-Finder achieved an F1-score of 0.818, significantly outperforming the function-level tool CENTRIS4J (F1-score of 0.391). It also demonstrated superior precision (0.698 vs. 0.270) and recall (0.986 vs. 0.706).
- Exceptional Efficiency: JC-Finder is considerably faster. Feature generation is about 4 times quicker than CENTRIS4J (52 hours vs. 220 hours). TPL recognition per project is about 9 times faster (14.2 seconds vs. 126.6 seconds) and more stable.
- Enhanced TPL Detection: JC-Finder detected 26.20% more TPLs that were not explicitly declared through package managers across 7,947 GitHub projects. This highlights its value in complementing traditional SCA methods.
- Ground Truth Construction: The paper introduces a manually constructed ground truth of clone-based TPL reuse for 1,000 GitHub projects, made publicly available.
Limitations and Future Work
- Reference Dataset Completeness: The accuracy of JC-Finder is dependent on the completeness of its Reference Dataset. If a library is not present, its reuse cannot be detected. Missing source code JARs for some artifacts can also lead to reduced recall.
- Ground Truth Completeness: While the ground truth is asserted to be sound, it may not be entirely complete due to insufficient detail in some cases.
- Trivial Function Threshold: The determination of what constitutes a "trivial" function is influenced by expert judgment, which can vary.
- Future Work: The authors suggest including more library sources in the Reference Dataset. They also propose dividing large libraries into smaller, specialized components to simplify tracking and reduce developer load. Additionally, they note that developers are increasingly encouraged to use packaged libraries over code cloning due to better version control and security updates.
Summary updated