INRIA / INRIA/spoon

[Bug]: Inconsistent between Spoon code and origin source code

Open
#5,288 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

When I try to analyze a class, I found that the code of sendSMS() in Spoon was different from the origin source code. The origin is "android.telephony.SmsManager sm = android.telephony.SmsManager.getDefault();", but it became "android.telephony.SmsManager sm = de.ecspride.SmsManager.getDefault();" in Spoon. The "android.telephony.SmsManager" became "de.ecspride.SmsManager", which's wrong. Seems that it's a bug.

### Source code you are trying to analyze/transform

```Java
package de.ecspride;

/* loaded from: classes.dex */
public class MainActivity extends android.app.Activity {
@Override // android.app.Activity
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(de.ecspride.R.layout.activity_main);
android.telephony.TelephonyManager telephonyManager = (android.telephony.TelephonyManager) getSystemService("phone");
java.util.Set phoneNumbers = new java.util.HashSet<>();
phoneNumbers.add("+49 123456");
phoneNumbers.add("+49 654321");
phoneNumbers.add("+49 111111");
phoneNumbers.add("+49 222222");
phoneNumbers.add("+49 333333");
int b = 33 + 43;
java.lang.String message = 33 == b ? "no taint" : telephonyManager.getDeviceId();
sendSMS(phoneNumbers, message);
}

private void sendSMS(java.util.Set numbers, java.lang.String message) {
android.telephony.SmsManager sm = android.telephony.SmsManager.getDefault();
for (java.lang.String number : numbers) {
sm.sendTextMessage(number, null, message, null, null);
}
}
}
```

### Source code for your Spoon processing

```Java
static String getRefName(String clsSourceCode, String targetSignature, String codeLine, String keyword, String param, int option) {
Launcher launcher = new Launcher();
launcher.addInputResource(new VirtualFile(clsSourceCode, "/path/to/MyClass.java"));
launcher.getEnvironment().setAutoImports(false);
launcher.buildModel();
CtModel model = launcher.getModel();
final String[] result = {null};

for (CtType ctType : model.getAllTypes()) {
CtMethod foundMethod = SpoonVisitor.getMethodWithSignature(ctType, targetSignature);
if (foundMethod != null) {
switch (option) {
case 1 -> {
CtBlock body = foundMethod.getBody();
String[] lines = clsSourceCode.split("\n");
for (CtStatement statement : body.getStatements()) {
if (lines[statement.getPosition().getLine() - 1].trim().equals(codeLine)) {
statement.accept(new CtScanner() {
@Override
public void visitCtInvocation(CtInvocation invocation) {
// invocation.getExecutable().getDeclaringType()
if (invocation.getExecutable().getSimpleName().equals(keyword)) {
if (!invocation.getTarget().toString().equals("")) {
result[0] = invocation.getTarget() + "." + invocation.getExecutable().getSimpleName() + "()";
} else {
result[0] = invocation.getExecutable().getSimpleName() + "()";
}
}
super.visitCtInvocation(invocation);
}
});
}
}
}
}
}
}
return result[0];
}
```

### Actual output

```Java
de.ecspride.SmsManager.getDefault()
```

### Expected output

```Java
android.telephony.SmsManager.getDefault()
```

### Spoon Version

10.4.0-beta-9

### JVM Version

19

### What operating system are you using?

MacOS 13.4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.