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]: Bug adding comment in AST of lambda #5661

Open
yijiangtian opened this issue Feb 7, 2024 · 2 comments
Open

[Bug]: Bug adding comment in AST of lambda #5661

yijiangtian opened this issue Feb 7, 2024 · 2 comments
Labels

Comments

@yijiangtian
Copy link

yijiangtian commented Feb 7, 2024

Describe the bug

An IndexOutBoundException occurs when a lambda has no arguments.

Bug position: JDTCommentBuilder.java:461

@Override
public <T> void visitCtLambda(CtLambda<T> e) {
	if (e.getExpression() != null) {
		CtParameter<?> lastParameter = e.getParameters().get(e.getParameters().size() - 1);   //  IndexOutBoundException 
		if (comment.getPosition().getSourceStart() > lastParameter.getPosition().getSourceEnd()) {
			e.getExpression().addComment(comment);
		} else {
			e.addComment(comment);
		}
	} else if (e.getBody() != null) {
		e.addComment(comment);
	}
}

Source code you are trying to analyze/transform

No response

Source code for your Spoon processing

   public static void main(String[] args) {
        Thread t = new Thread(() -> /* comments here */ System.out.println("Thread " + Thread.currentThread().getId() + " is running"));
        t.start();
    }

Actual output

No response

Expected output

No response

Spoon Version

10.4.2

JVM Version

11

What operating system are you using?

win10

@yijiangtian yijiangtian added the bug label Feb 7, 2024
@SirYwell
Copy link
Collaborator

SirYwell commented Feb 7, 2024

Do you have example code that triggers this bug?

@yijiangtian
Copy link
Author

Added example code

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

No branches or pull requests

2 participants