SpoonLabs / astor

Automatic program repair for Java with generate-and-validate techniques :v::v:: jGenProg (2014) - jMutRepair (2016) - jKali (2016) - DeepRepair (2017) - Cardumen (2018) - 3sfix (2018)
https://hal.archives-ouvertes.fr/hal-01321615/document
GNU General Public License v2.0
205 stars 106 forks source link

Cardumen single change, expected different result #305

Closed MaximoOliveira closed 3 years ago

MaximoOliveira commented 3 years ago

Hello @martinezmatias !

I'm testing something on Cardumen and am getting a different result than the expected. I've tried a couple of things and had no success. Maybe you could know what is causing this problem

Sorry for the long post :p I appreciate any help you can give!

I've made the following single change on Cardumen: Removed part of code ''|| element instanceof CtVariableAccess", so that variables are also considered in the search space. https://github.com/SpoonLabs/astor/blob/28b285b4ff41ce65affc537a54e4ea4300a6d1ef/src/main/java/fr/inria/astor/core/manipulation/filters/ExpressionIngredientSpaceProcessor.java#L30

And tested this change with the program DETECT_CYCLE from QuixBugs: https://github.com/KTH/quixbugs-experiment/blob/master/src/main/java/java_programs/DETECT_CYCLE.java

With these changes we should see that when the modification point at line 21 is the expression tortoise.getSuccessor(): image

We should have an ingredient in the form: _Node_0 , which we currently get: image

However when the transformation is done: image

the variables present do not replace the template _Node_0: image

The ingredientsAfterTransformation list has 3 DynamicIngredient all with the shown expection, and when evaluating them the Ingredients are in the form: _Node_0 and not hare , (as expected)

I leave the test case here in case it helps: `public void test_detect_cycle_cardumen() throws Exception { AstorMain main1 = new AstorMain();

    CommandSummary command = (getQuixBugsCommand("detect_cycle"));
    command.command.put("-maxgen", "0");
    command.command.put("-mode", "cardumen");
    main1.execute(command.flat());

    CardumenApproach cardumen = (CardumenApproach) main1.getEngine();

    ExpressionTypeIngredientSpace ingredientSpace = (ExpressionTypeIngredientSpace) cardumen
            .getIngredientSearchStrategy().getIngredientSpace();
    ProbabilisticIngredientStrategy ingredientStrategy = (ProbabilisticIngredientStrategy) cardumen.getIngredientSearchStrategy();
    IngredientTransformationStrategy transformationStrategy = ingredientStrategy.getIngredientTransformationStrategy();
    ProgramVariant pvar = cardumen.getVariants().get(0);
    // ********************************************************************************************************//
    //Relevant test part starts here

    // The expression on line 21: tortoise.getSuccessor()
    CtElement suspiciousElement = getSuspiciousElement(pvar, "tortoise.getSuccessor()", 21);
    ModificationPoint modPoint = pvar.getModificationPoint(suspiciousElement);

    List<Ingredient> ingredients = ingredientSpace.getIngredients(suspiciousElement);
    // the template ingredient _Node_0
    Ingredient ingredient = ingredients.stream().filter(i ->
            i.toString().equals("_Node_0")).findFirst().orElse(null);

    /*  Im expecting 3 possible transformations to the _Node_0 template:
     *        {hare, tortoise, node}
     *   However i just get the ingredients: {_Node_0, _Node_0, _Node_0}
     */
    List<Ingredient> ingredientsAfterTransformation = transformationStrategy.transform(modPoint, ingredient);
    assert (ingredientsAfterTransformation.stream().anyMatch(i ->
            i.toString().equals("hare"))); // this assert will fail
}`
martinezmatias commented 3 years ago

Hi @MaximoOliveira

Thanks for the detailed report of the issue.

One question: If you don't apply the change you mention in the if (i.e., reducing the expression from the condition). Do you have the same issue? i.e., the ingredients are not transformed.

Regards Matias

MaximoOliveira commented 3 years ago

Hi @martinezmatias

If I dont apply the changes the ingredient _Node_0 does not appear:

image

Instead of 5 ingredients we have 3.

The transformations for these 3 ingredients are applied

martinezmatias commented 3 years ago

I see, so that means that the bug (ingredients are not transformed) only appears when we include the CtVariables in the list of ingredients, right?

MaximoOliveira commented 3 years ago

Correct!

martinezmatias commented 3 years ago

okey, thanks. I would say that CtVariable should not include as ingredients because they are not expressions thus, they cannot be evaluated (and Cardumen needs to evaluate the ingredient in order to replace one piece of code per another with compatible type). An ingredient could be a CtVariableAccess (in particular CtVariableRead) which in that case the ingredient could be evaluated.

MaximoOliveira commented 3 years ago

Thank you!