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] toString crashes due to comment handling #3381

Closed
santos-samuel opened this issue May 25, 2020 · 4 comments
Closed

[BUG] toString crashes due to comment handling #3381

santos-samuel opened this issue May 25, 2020 · 4 comments

Comments

@santos-samuel
Copy link
Contributor

santos-samuel commented May 25, 2020

Hello,
I just came across an error.

When I add certain classes as input resources to the launcher, Spoon, when building the model, will only partially parse the class and throw an error that is shown on some fields saying:
Method threw 'spoon.SpoonException' exception. Cannot evaluate spoon.support.reflect.declaration.CtClassImpl.toString()

And when I call the toString method it says:
spoon.SpoonException: Unexpected next line after last line

It's not that I care about the toString() method, but this error is not allowing me, for instance, to get the Executable Declaration of a method based on its executable. (actually this error was coming from another place)

I created a PR with two failing test cases so you can inspect it:
#3382

Thanks in advance!

EDIT1:
After some debugging I found that the error is on class JDTCommentBuilder.java on line 608.
I believe the problem is that you are not considering line comments inside block comments, for example:

            /*
            // Set the SecurityContextHolder authentication to null
            SecurityContextHolder.getContext().setAuthentication(null);

            // Call the commence method of authenticationEntryPoint
            authenticationEntryPoint.commence(request,response,new BadCredentialsException("IP not allowed"));
            */

When the code sees the first '/' on the first line of the comment it will immediatly do isLastLine = true;. And then the second line SecurityContextHolder.getContex (...) will throw the error.

@santos-samuel
Copy link
Contributor Author

If the comments are not needed I believe this fixes eventual problems:
launcher.getEnvironment().setCommentEnabled(false);

@monperrus
Copy link
Collaborator

monperrus commented May 26, 2020 via email

nharrand added a commit to santos-samuel/spoon that referenced this issue May 26, 2020
@santos-samuel
Copy link
Contributor Author

Thanks for the bug report. What happens if you call toStringDebug instead of toString?

toStringDebug() seems to be working fine. It does not throw the Exception

@monperrus monperrus changed the title [BUG] To String Error [BUG] toString crashes due to comment handling May 26, 2020
@santos-samuel
Copy link
Contributor Author

Since the PR was merged already i'm closing this issue

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

No branches or pull requests

2 participants