INRIA / INRIA/spoon

[Bug]: Simple case with wrong package name of used external class

Open
#5,150 0 comments 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 asking to parse 2 classes a.A & b.B and a.A is using an external class c.C through b.B (see simple code below), the parser reports that a.A is using b.C instead of c.C (C belongs to package c and not b).

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

```Java
// First file A.java
package a;

import b.B;

public class A {

public static void callC(B b) {
b.getC().xxx();
}

}

// Second file B.java
package b;

import c.C; // external source not provided

public interface B {

C getC();

}
```

### Source code for your Spoon processing

```Java
Launcher launcher = new Launcher();
launcher.addInputResource(inputSource);
CtModel model = launcher.buildModel();

for (CtElement ctClass : model.getElements(e -> e instanceof CtClass || e instanceof CtInterface)) {
CtType ctType = (CtType) ctClass;
System.out.println(ctType.getQualifiedName() + " is using:");
for (CtTypeReference type : ctType.getUsedTypes(true)) {
System.out.println(" - " + type.getQualifiedName());
}
}
```

### Actual output

```Java
a.A is using:
- b.C
- b.B
b.B is using:
- c.C
```

### Expected output

```Java
a.A is using:
- c.C
- b.B
b.B is using:
- c.C
```

### Spoon Version

10.3.0

### JVM Version

11

### What operating system are you using?

macOS 11.7.4 (BigSur) - IntelliJ IDEA 2023.1

Contributor guide

Open the contributing guide

Research direction

Start with the Launcher.buildModel() entry point and the CtType.getUsedTypes(true) and CtTypeReference.getQualifiedName() calls shown in the report. Reproduce the case using A.java and B.java, with external C unavailable, then trace type resolution for A's b.getC() call. Done means A reports c.C rather than b.C while B continues to report c.C.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.