INRIA / INRIA/spoon

[Bug]: Bug adding comment in AST of lambda

Open
#5,661 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

An IndexOutBoundException occurs when a lambda has no arguments.

**Bug position:** JDTCommentBuilder.java:461

``` java
@Override
public void visitCtLambda(CtLambda 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

```java
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

Contributor guide

Open the contributing guide

Research direction

Start in JDTCommentBuilder.java at line 461 and reproduce the failure with the no-argument lambda shown in the issue. Verify the comment-handling path for a lambda with no parameters; done means the analysis completes without IndexOutOfBoundsException and attaches the comment as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.