This repository is used to replicate the experiments of article "Detecting, Creating, Repairing, and Understanding Indivisible Multi-Hunk Bugs" on Hercules.
"Harnessing Evolution for Multi-Hunk Program Repair" proposes Hercules. Since the source code is not provided by the authors, we implement Hercules in this repository according to the description in the paper.
We only reproduced the Hercules-MinusHistory.
We use the GZoltar to identify potential repair locations. The formula we used in GZoltar is Ochiai.
① We use soot to extract program context.
② When comparing two AST nodes N1 and N2, we only use kind compatibility and name similarity. Because there are some nodes, the JDT cannot get their type.
We completed the stages of building an abstract syntax tree and generating patches based on TBar.
① We change the a field isTestFixPatterns
in edu.lu.uni.serval.tbar.AbstractFixer
from false to true, so that it can generate more plausible patches.
② We removed some templates and kept only the templates used in PAR, ACS, Elixir, which are cited by the authors in the Implementation part.
③ We transform the patches generated by TBar according to this rule.
We use ODS to rank the candidate patches, which is also a learning-based ranking model. Because we do not have the ranking model similar to Elixir.
- JDK 1.8
- Python 3.8
- Defects4J 2.0.0
- CatenaD4J
- Timeout: 5h
None
Use the Dockerfile
in ./Docker
to create the docker image.
docker build -t hercules-env .
This docker image includes Defects4J, CatenaD4J, JDK 1.8, and Python 3.8.
docker run -it --name hercules hercules-env /bin/bash
At the root of this container, we clone the Hercules repository.
cd /
git clone https://github.com/give-to/Hercules.git
cd /Hercules && chmod +x *
After testing, we found that using pip in the Docker file might cause image creation to fail, so configuration inside the container is required.
# Preparing the environment
pip install -r requirements.txt
It takes several minutes to quickly test your installation. (Note: In quick test, the ochiai.ranking.txt
in Chart_18_2 only contains one location! )
cp location/105SampleBugsResult/Chart_18_2/short.txt location/105SampleBugsResult/Chart_18_2/ochiai.ranking.txt
# Test your environment
./run.sh /CatenaD4JProjects /CatenaD4J ./location/105SampleBugsResult ./test.txt
After finishing the repair, the results are in folders: patches
and results
.
patches
: The generated patches. Its structure is as follows:
patches
|--- Chart_2_5 : bugid
|------ group_1 : the first siblings
|--------- 0.txt : specific patches, each row is a partial patch
|------ group_2 : the second siblings
|--------- 0.txt : specific patches, each row is a partial patch
results
: The validation results. The plausible patch will showPass
.
It may take about 22 days to finish the entire experiment. You can also modify 105_bugs_list.txt
to determine the bugs to be fixed.
cp location/105SampleBugsResult/Chart_18_2/backup.txt location/105SampleBugsResult/Chart_18_2/ochiai.ranking.txt
rm -rf patches/ results/
# Run the whole experiment
./run.sh /CatenaD4JProjects /CatenaD4J ./location/105SampleBugsResult ./105_bugs_list.txt
After finishing the repair, the results are in folders: patches
and results
.
In the Hercules directory:
./run.sh <ProjectsRoot> <CatenaD4JHome> <FLroot> <bugListFile>
Where:
ProjectsRoot
: the root directory that you want to checkout all CatenaD4J bugs in.CatenaD4JHome
: the root directory of CatenaD4J.FLroot
: the root directory of ochiai results of all bugs.bugListFile
: a file contains all the bugs to be fixed.
The Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar
in the root directory contains 3 parts, finding siblings, patch generation and patch ranking. It saves all patches and patch ranking results in patches
directory. It accepts 4 parameters:
java -cp Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar org.example.hercules.Main_NFL <ProjectsRoot> <CatenaD4JHome> <FLroot> <bugListFile>
Where:
ProjectsRoot
: the all buggy projects' root directory.
ProjectRootDir
| Chart_1_1
| |
| |
| Chart_1_2
| |
| |
CatenaD4JHome
: the root directory of CatenaD4J.FLRoot
: the root directory of fault localization results. (The file name of fault localization results must beochiai.ranking.txt
.)
FLRoot
| Chart_1_1
| | ochiai.ranking.txt
| Chart_1_2
| | ochiai.ranking.txt
bugListFile
: A file contains all projectsId that you want to repair.
Example:
# You should have checked out the bugs first.
java -cp Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar /CatenaD4JProjects CatenaD4J ./location/105SampleBugsResult ./105_bugs_list.txt
The hercules_valid_v2.py
will validate patches under patches
directory according to patch ranking results, until all patches have been validated or timed out. The patch that shows Pass is the plausible patch
. It accepts 1 parameter:
python3 hercules_valid_v2.py <ProjectsRoot>
ProjectsRoot
: the all buggy projects' root directory.
Example:
# You should have checked out the bugs and generated the patches first.
python3 hercules_valid_v2.py /CatenaD4JProjects
|--- README.md : User guidance
|--- C4J_results : Patches and results of CatenaD4J bugs
|--- Docker : Dockerfile
|--- location : Bug positions localized with GZoltar of CatenaD4J bugs
|--- scripts : Apply patches to projects
|--- src : Source code