spoon icon indicating copy to clipboard operation
spoon copied to clipboard

[Bug]: Cannot compute access path to type

Open JoneZhu opened this issue 2 years ago • 2 comments

Describe the bug

Exception: image

  1. ClueTrackActionServiceImpl is in project source
  2. com.shuidihuzhu.sdb.broker.enums.ActionStatus is in jar
  3. 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

JoneZhu avatar Mar 01 '23 11:03 JoneZhu

1 . can not compute "MEET_CONSULT" path to ClueTrackActionServiceImpl ,analysis exception source code , the bug is in CtTypeReference 767 canAcess method. image 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, image

  1. Class Definece is class ActionStatus{} , why ActionStatus is not null image image when SpoonClassNotFoundException happen, spoon.support.compiler.jdt.ContextBuilder#getVariableDeclaration(java.lang.String, java.lang.Class<U>) create ActionStatus CtType.

JoneZhu avatar Mar 01 '23 12:03 JoneZhu

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.

learjet5 avatar Jan 06 '24 06:01 learjet5