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

Bug - modification point is pointing to a spoon element that has a NoSourcePosition #301

Closed MaximoOliveira closed 3 years ago

MaximoOliveira commented 3 years ago

For context see bug 1) from #298

This can be solved by adding a condition to check that a ctElement's position is not an instance of NoSourcePosition:

Replace this loop https://github.com/SpoonLabs/astor/blob/df11be14321b522b8deab115ef902ae8e097e1f5/src/main/java/fr/inria/astor/core/solutionsearch/population/ProgramVariantFactory.java#L181

By :

for (CtElement suspiciousElement : extractedElements) {

                if (!(suspiciousElement.getPosition() instanceof NoSourcePosition)) {
                    List<CtVariable> contextOfGen = VariableResolver.searchVariablesInScope(suspiciousElement);

                    SuspiciousModificationPoint point = new SuspiciousModificationPoint();
                    point.setSuspicious(new SuspiciousCode(ctclasspointed.getQualifiedName(), "",
                            suspiciousElement.getPosition().getLine(), 0d, null));
                    point.setCtClass(ctclasspointed);
                    point.setCodeElement(suspiciousElement);
                    point.setContextOfModificationPoint(contextOfGen);
                    suspGen.add(point);
                    log.info("--ModificationPoint:" + suspiciousElement.getClass().getSimpleName() + ", suspValue "
                            + point.getSuspicious().getSuspiciousValue() + ", line "
                            + suspiciousElement.getPosition().getLine() + ", file "
                            + suspiciousElement.getPosition().getFile().getName());

                    if (suspGen.size() > maxModPoints) {
                        log.info("Reducing Total ModPoint created to: " + maxModPoints);
                        return suspGen;
                    }
                }
            }

And this loop: https://github.com/SpoonLabs/astor/blob/df11be14321b522b8deab115ef902ae8e097e1f5/src/main/java/fr/inria/astor/core/solutionsearch/population/ProgramVariantFactory.java#L257

By:

for (CtElement ctElement : filteredTypeByLine) {
            if (!(ctElement.getPosition() instanceof NoSourcePosition)) {
                SuspiciousModificationPoint modifPoint = new SuspiciousModificationPoint();
                modifPoint.setSuspicious(suspiciousCode);
                modifPoint.setCtClass(ctclasspointed);
                modifPoint.setCodeElement(ctElement);
                modifPoint.setContextOfModificationPoint(contextOfPoint);
                suspiciousModificationPoints.add(modifPoint);
                log.debug("--ModifPoint:" + ctElement.getClass().getSimpleName() + ", suspValue "
                        + suspiciousCode.getSuspiciousValue() + ", line " + ctElement.getPosition().getLine() + ", file "
                        + ((ctElement.getPosition().getFile() == null) ? "-null-file-"
                        : ctElement.getPosition().getFile().getName()));
            }

        }

What do you think @martinezmatias ?

martinezmatias commented 3 years ago

Hi @MaximoOliveira

Thanks for the proposed changes. So, If I well understood the changes, those add a guard that check the filtered element is has a SourcePosition, right?

Thanks! Regards Matias

martinezmatias commented 3 years ago

Hi @MaximoOliveira

It would be nice if you create a PR with those two changes and a test case that exposes the problem and assert the new behaviour i.e., to assert that no modification point targets a NoSourcePosition element.

Thanks! Regards Matias

MaximoOliveira commented 3 years ago

Hi @martinezmatias

Thanks for the proposed changes. So, If I well understood the changes, those add a guard that check the filtered element is has a SourcePosition, right?

Correct!

It would be nice if you create a PR with those two changes and a test case that exposes the problem and assert the new behaviour i.e., to assert that no modification point targets a NoSourcePosition element.

I can open a pr with that today or tomorrow!

Thank you!

martinezmatias commented 3 years ago

Great thanks!