spoon
spoon copied to clipboard
[Bug]: Cannot compute access path to type
Describe the bug
Exception:

- ClueTrackActionServiceImpl is in project source
- com.shuidihuzhu.sdb.broker.enums.ActionStatus is in jar
- MavenLauncher.Environment.noclasspath is true
Source code you are trying to analyze/transform
import static com.shuidihuzhu.sdb.broker.enums.ActionStatus.MEET_CONSULT;
@Service
@Slf4j
public class ClueTrackActionServiceImpl {
public String getTitle(TrackAction trackAction, TrackStatus trackStatus) {
if (MEET_CONSULT.equals(trackAction.getStatus())) {
return String.format("%s%s", ACTION_TITLE_PREFIX, trackAction.getStatus().getTrackProgress().getMsg());
}
return trackAction.getStatus().getMsg();
}
}
Source code for your Spoon processing
String projectPath = codePath + "/" + projectName;
log.info("加载工程[{}] projectPath[{}] begin", projectName, projectPath);
MavenLauncher launcher = null;
if (isLocalDebug) {
launcher = new MavenLauncher(projectPath, MavenLauncher.SOURCE_TYPE.APP_SOURCE);
} else {
launcher = new MavenLauncher(projectPath, MavenLauncher.SOURCE_TYPE.APP_SOURCE, Constant.MVN_FILE);
}
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().disableConsistencyChecks();
launcher.getEnvironment().setIgnoreDuplicateDeclarations(true);
launcher.getEnvironment().setNoClasspath(true);
//launcher.getEnvironment().setLevel(Level.DEBUG.name());
//launcher.getEnvironment().setIgnoreSyntaxErrors(true);
launcher.setSourceOutputDirectory(codePath + "/" + projectName + "transformed");
launcher.run();
Actual output
No response
Expected output
No response
Spoon Version
10.3.0
JVM Version
11
What operating system are you using?
macos 12.3.1
1 . can not compute "MEET_CONSULT" path to ClueTrackActionServiceImpl ,analysis exception source code , the bug is in CtTypeReference 767 canAcess method.
except canAcess return true , actual canAcess return false
2. ActionStatus is in jar,this is no ActionStatus CtType; except type is null , actual type not null,

- Class Definece is class ActionStatus{} , why ActionStatus is not null
when SpoonClassNotFoundException happen, spoon.support.compiler.jdt.ContextBuilder#getVariableDeclaration(java.lang.String, java.lang.Class<U>) create ActionStatus CtType.
I've met the same question. When MavenLauncher.Environment.noclasspath is set true, "spoon.SpoonException: Cannot compute access path to type: xxx" should not be raised. Hope this bug can be solved soon.