eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

Missing return in lamdas confuses JDT

Open
#764 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
22h 47m
Merged PRs (30d)
28

Description

This is similar to a problem described already here:
- https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/759

Assume the following code:

```
CompletableFuture.supplyAsync(()->{

});
```

This results in these quick fixes:

![grafik](https://github.com/eclipse-jdt/eclipse.jdt.ui/assets/1331477/9be17021-d7f2-46e5-98ac-5d165b604b43)

of course neither of those produce any useful results, the first results in

```
CompletableFuture.supplyAsync((Supplier)()->{

});
```

the second (now with the same error):
```
CompletableFuture.thenApplyAsync(()->{

});
```

if one instead performs the refactoring "Convert to anonymous class creation",

![grafik](https://github.com/eclipse-jdt/eclipse.jdt.ui/assets/1331477/59ec1d0d-d199-4385-aa5f-02788256e7c3)

the problem becomes a bit more clear:

```
CompletableFuture.supplyAsync(new Supplier() {
@Override
public U get() {

}
});
```

even though `U` is not really a valid choice, so we replace `U` with `Object`:

```
CompletableFuture.supplyAsync(new Supplier<>() {

@Override
public Object get() {

}
});
```
Finally we got what we would like have seen in the first place, **adding the missing return statement!**

![grafik](https://github.com/eclipse-jdt/eclipse.jdt.ui/assets/1331477/c85eb5c0-3262-4840-9863-f2890ac3bd39)

Now one can choose to "convert to lamda expression" refactoring to get to a working state again...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.