Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Unknown source position when using lambda in inner class #3052

Closed
aveuiller opened this issue Jul 18, 2019 · 4 comments · Fixed by #3056
Closed

bug: Unknown source position when using lambda in inner class #3052

aveuiller opened this issue Jul 18, 2019 · 4 comments · Fixed by #3056
Labels

Comments

@aveuiller
Copy link
Contributor

aveuiller commented Jul 18, 2019

Hello,

I have a quite weird behavior in my processor when analyzing this class: https://github.com/woffs/tazapp-android/blob/master/tazapp/src/main/java/de/thecode/android/tazreader/reader/usertoc/UserTocAdapter.java#L180-L191

I tracked down the bug to this minimal code sample:

public class Test {
    public static class Failing {
        Any listener;
    }

    private static class ExtendedClass extends Failing {
        public void test() { 
           // The difference in behaviour happens if I comment this line out
           Runnable r = v -> listener.someAction();
        }
    }
}

Here, the class Failing will have a position returning (uknown file) in my processor if the line with the lambda stays uncommented.
My processor will work fine if I comment it out though.

You will find as follow the configuration of my spoon launcher:

        Launcher launcher = new Launcher();

        launcher.addInputResource(appPath);
        launcher.getEnvironment().setNoClasspath(true);
        launcher.buildModel();

        AbstractProcessor<CtClass> classProcessor = new ClassProcessor();
        AbstractProcessor<CtInterface> interfaceProcessor = new InterfaceProcessor();
        launcher.addProcessor(classProcessor);
        launcher.addProcessor(interfaceProcessor);
        launcher.process();

And I will also attach the two states from my debugger.
Do you have an idea of the issue? Anything I can do about it?

Thanks in advance.

2019-07-18-233325_565x504_scrot
2019-07-18-233420_1045x419_scrot

@monperrus
Copy link
Collaborator

monperrus commented Jul 19, 2019 via email

@aveuiller
Copy link
Contributor Author

Hello Martin,

You are correct. In my processor, I am using the position attribute to store the path to the file holding the processed class, but in this case I am not able to retrieve it.

By the way, I forgot to mention but I'm using the version 7.4.0.

@monperrus
Copy link
Collaborator

So this is a bug. Would you create a pull-request with a failing test case? Thanks!

@monperrus monperrus added the bug label Jul 19, 2019
@monperrus monperrus changed the title Unknown File in processor when using lambda in inner class bug: Unknown source position when using lambda in inner class Jul 19, 2019
aveuiller pushed a commit to aveuiller/spoon that referenced this issue Jul 20, 2019
aveuiller pushed a commit to aveuiller/spoon that referenced this issue Jul 20, 2019
aveuiller pushed a commit to aveuiller/spoon that referenced this issue Jul 20, 2019
aveuiller pushed a commit to aveuiller/spoon that referenced this issue Jul 20, 2019
aveuiller pushed a commit to aveuiller/spoon that referenced this issue Jul 20, 2019
@aveuiller
Copy link
Contributor Author

A reproduction of the bug is available in #3054

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants