SpoonLabs / coming

A tool for mining commits from Git repositories and diffs to automatically extract code change pattern instances and features with ast analysis
https://hal.inria.fr/hal-00861883/file/paper-short.pdf
MIT License
93 stars 33 forks source link

CodeFeatures not being generated #259

Closed Sin-Mim closed 8 months ago

Sin-Mim commented 9 months ago

Hi, I'm trying to run Coming in feature mode. I installed the project with maven. When I run java -classpath ./target/coming-0-SNAPSHOT-jar-with-dependencies.jar fr.inria.coming.main.ComingMain -location ./files2compare -input files -mode features -output ./out. I get context and repair pattern features but code features are not being generated. Also, I'm getting errors/warnings below,

log4j:WARN File option not set for appender [file].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR No output stream or file set for the appender named [file].
java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "spoon.reflect.code.CtInvocation.getTarget()" is null
        at fr.inria.coming.codefeatures.codeanalyze.LogicalExpressionAnalyzer.analyzeLE7_VarDirectlyUsed(LogicalExpressionAnalyzer.java:684)
        at fr.inria.coming.codefeatures.codeanalyze.LogicalExpressionAnalyzer.analyze(LogicalExpressionAnalyzer.java:59)
        at fr.inria.coming.codefeatures.CodeFeatureDetector.analyzeFeatures(CodeFeatureDetector.java:50)
        at fr.inria.coming.codefeatures.CodeFeatureDetector.analyzeFeatures(CodeFeatureDetector.java:96)
        at fr.inria.coming.codefeatures.FeatureAnalyzer.analyze(FeatureAnalyzer.java:88)
        at fr.inria.coming.core.engine.RevisionNavigationExperiment.analyze(RevisionNavigationExperiment.java:127)
        at fr.inria.coming.main.ComingMain.start(ComingMain.java:147)
        at fr.inria.coming.main.ComingMain.run(ComingMain.java:140)
        at fr.inria.coming.main.ComingMain.main(ComingMain.java:124)
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
14:01:00.084 [main] DEBUG add.features.detector.spoon.SpoonHelper - InsertOperation
14:01:00.085 [main] DEBUG add.features.detector.spoon.SpoonHelper - org.jfree.chart.renderer.AbstractRenderer

14:01:00.085 [main] DEBUG add.features.detector.spoon.SpoonHelper - Insert ...

Am I missing something?

monperrus commented 9 months ago

it seems that one input file cannot be correctly parsed with Spoon.

could you try to add a guard at LogicalExpressionAnalyzer.java:684?

Sin-Mim commented 9 months ago

Thanks for the support. I applied the patch below

diff --git a/src/main/java/fr/inria/coming/codefeatures/codeanalyze/LogicalExpressionAnalyzer.java b/src/main/java/fr/inria/coming/codefeatures/codeanalyze/LogicalExpressionAnalyzer.java
index 12051ac3..e1b47f87 100755
--- a/src/main/java/fr/inria/coming/codefeatures/codeanalyze/LogicalExpressionAnalyzer.java
+++ b/src/main/java/fr/inria/coming/codefeatures/codeanalyze/LogicalExpressionAnalyzer.java
@@ -681,7 +681,7 @@ public class LogicalExpressionAnalyzer extends AbstractCodeAnalyzer {

                for (CtInvocation invocation : invocationssInStatement) {

-                   if(!invocation.getTarget().toString().isEmpty()) {
+                   if(invocation.getTarget() != null && !invocation.getTarget().toString().isEmpty()) {
                        continue;
                    }

I am not getting the NullPointerException anymore, but the code description features are still not being generated and there are still the following errors/warnings.

log4j:WARN File option not set for appender [file].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR No output stream or file set for the appender named [file].

I also tried it on the simple code below

// Math_70_BisectionSolver_s.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Foo!");
    }
}
// Math_70_BisectionSolver_t.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

and got the same results (the warnings and the error above).

monperrus commented 9 months ago

this works for me.

    @Test
    public void testissue259() throws Exception {

        //java - classpath. / target / coming - 0 - SNAPSHOT - jar - with - dependencies.jar fr.inria.coming.main.ComingMain - location. / files2compare - input files - mode features - output. / out

        fr.inria.coming.main.ComingMain.main(new String[] { "-location", "./repogit4testv0", "-input", "git", "-output", "out", "-mode", "features" });

    }

can you try in input git instead of files?

Sin-Mim commented 8 months ago

I found that after adding the guard at LogicalExpressionAnalyzer.java:684, Coming was actually generating the features correctly for both files and git input types. I appreciate your support.

monperrus commented 8 months ago

Great, could you send a pull-request with the fix?

Sin-Mim commented 8 months ago

I have created a pull request regarding this issue.