Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
248 stars 60 forks source link

memberCallExpression is mistakenly parsed as staticCallExpression due to the package path of import #1026

Closed z2Z6 closed 1 year ago

z2Z6 commented 1 year ago

Unexpected behavior

The node type of test.doSomething on line 6 is affected by package path on first line. If penultimate package name which ends with .* is the same as base name of memberCallExpression, then the memberCallExpression will be mistakenly parsed as staticCallExpression, e.g. node on line 6. Modify package name "test" on first line to others, the node type is parsed as memberCallExpression correctly.

Code of interest

package structure

|--com
   |--test
      |--Test.java
|--Sample.java

Sample.java

import com.test.*;  // line 1

public class Sample {
    public void func() {
        Test test = new Test();
        test.doSomething();  // line 6
    }
}

Configuration

v5.1.0

new TranslationConfiguration.Builder()
                .sourceLocations(new File(filename))
                .defaultPasses()
                .defaultLanguages()
                .build();
KuechA commented 1 year ago

Hi @z2Z6 ,

thank you for opening the issue. Could you please check if the PR #963 solves the problem by chance? We're currently working on improving the naming system (which is almost done) and afterwards we'll work on the symbol/call resolution since they are related to each other. So please stay tuned :)

z2Z6 commented 1 year ago

Hi @z2Z6 ,

thank you for opening the issue. Could you please check if the PR #963 solves the problem by chance? We're currently working on improving the naming system (which is almost done) and afterwards we'll work on the symbol/call resolution since they are related to each other. So please stay tuned :)

Unfortunately, it doesn't seem to work on the main branch now. I will open issues I encounter if they can be describled clearly, look forward to the next version.

oxisto commented 1 year ago

Hi @z2Z6 , thank you for opening the issue. Could you please check if the PR #963 solves the problem by chance? We're currently working on improving the naming system (which is almost done) and afterwards we'll work on the symbol/call resolution since they are related to each other. So please stay tuned :)

Unfortunately, it doesn't seem to work on the main branch now. I will open issues I encounter if they can be describled clearly, look forward to the next version.

I can confirm that this is now definitely fixed in #1031

z2Z6 commented 1 year ago

The problem is solved, thanks.

oxisto commented 1 year ago

Looks like I can reproduce this even with #1031 under certain cirumstances. I will have another look and add a test to the #1031 PR.

z2Z6 commented 1 year ago

Hi @oxisto, There seem to be another problem, if Sample.java is in the package path which is the same as Test.java. In this case, there is no need to import package path of Test.java for Sample.java.

package structure

|--com
   |--Test.java
   |--Sample.java

Sample.java

package com;

public class Sample {
    public void func() {
        Test.doSomething();  // The attribute `isStatic` of MemberCallExpression is false
    }
}
oxisto commented 1 year ago

Hi @oxisto, There seem to be another problem, if Sample.java is in the package path which is the same as Test.java. In this case, there is no need to import package path of Test.java for Sample.java.

package structure

|--com
   |--Test.java
   |--Sample.java

Sample.java

package com;

public class Sample {
    public void func() {
        Test.doSomething();  // The attribute `isStatic` of MemberCallExpression is false
    }
}

Interesting. Seems this a different, but related issue. Could you maybe open a second issue for this specifically? I do not want to have too many problems in one single issue :)

z2Z6 commented 1 year ago

The issue is opened in #1041.