Repository: fraunhofer-aisec/cpg
Issue: FQN wrong for some static calls

For the following snippet, the fqn is `Cipher.getInstance(...)` but should be `javax.crypto.Cipher.getInstance(...)`

```java
import javax.crypto.Cipher;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class BCProviderCipher {

	public static void main(String[] args) {
		Cipher c4 = Cipher.getInstance("AES", new BouncyCastleProvider());
	}
}
```

This probably has something to do with `BouncyCastleProvider` not being available. But still, the CPG could "guess" the fqn quite easily here i imagine

Changed files:
src/main/java/de/fraunhofer/aisec/cpg/graph/StaticCallExpression.java, src/main/java/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.java, src/main/java/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.java

diff --git a/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.java b/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.java
index abeb65285..716907aaf 100644
--- a/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.java
+++ b/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.java
@@ -654,9 +654,13 @@ public class ExpressionHandler
             NodeBuilder.newMemberCallExpression(
                 name, qualifiedName, base, member, methodCallExpr.toString());
       } else {
+        String targetClass = this.lang.getQualifiedNameFromImports(scopeName);
+        if (targetClass == null) {
+          targetClass = scopeName;
+        }
         callExpression =
             NodeBuilder.newStaticCallExpression(
-                name, qualifiedName, methodCallExpr.toString(), scopeName);
+                name, qualifiedName, methodCallExpr.toString(), targetClass);
       }
     } else {
       callExpression =
diff --git a/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.java b/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.java
index e0fea0374..47667534e 100644
--- a/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.java
+++ b/src/main/java/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.java
@@ -323,7 +323,7 @@ public class JavaLanguageFrontend extends LanguageFrontend {
   }
 
   public String getQualifiedNameFromImports(String className) {
-    if (context != null) {
+    if (context != null && className != null) {
       List<String> potentialClassNames = new ArrayList<>();
       String prefix = "";
       for (String s : className.split("\\\\.")) {
diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/StaticCallExpression.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/StaticCallExpression.java
index 38d496083..fa1fe04b8 100644
--- a/src/main/java/de/fraunhofer/aisec/cpg/graph/StaticCallExpression.java
+++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/StaticCallExpression.java
@@ -26,6 +26,8 @@
 
 package de.fraunhofer.aisec.cpg.graph;
 
+import org.checkerframework.checker.nullness.qual.NonNull;
+
 /**
  * A {@link CallExpression} that targets a static function of a different {@link RecordDeclaration},
  * without using a static import: <code>SomeClass.invoke()</code>
@@ -38,7 +40,20 @@ public class StaticCallExpression extends CallExpression {
     return targetRecord;
   }
 
+  @Override
+  public void setName(@NonNull String name) {
+    super.setName(name);
+    updateFqn();
+  }
+
   public void setTargetRecord(String targetRecord) {
     this.targetRecord = targetRecord;
+    updateFqn();
+  }
+
+  private void updateFqn() {
+    if (targetRecord != null && !targetRecord.isEmpty() && name != null && !name.isEmpty()) {
+      setFqn(targetRecord + "." + name);
+    }
   }
 }