apache / apache/netbeans

NetBeans doesn't recognize annotation on function return type with source formatting

Open
#7,535 3 comments 0 reactions 0 assignees View on GitHub
Editor Java kind:bug
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 22

### What happened

NB formats code in a wrong way when annotation is used for function return type.

### Language / Project Type / NetBeans Component

Java Maven Project using Java Modules (JPMS)

### How to reproduce

Create NewClass:

```
import org.jetbrains.annotations.NotNull;

public class NewClass {

public @NotNull String doItNow() {
return null;
}
}
```
And press ALT + SHIFT + F to format the code. You will get this result:
```
import org.jetbrains.annotations.NotNull;

public class NewClass {

public @NotNull
String doItNow() {
return null;
}
}
```

The same happens for class fields:
```
private final @Nullable List foos;
```
### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Ubuntu 20.04.3 LTS

### JDK

Java: 21.0.2; OpenJDK 64-Bit Server VM 21.0.2+13-58

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in Apache NetBeans 22 with the provided Java Maven example and source-formatting shortcut. Start at the Java source formatter entry point and trace handling of annotations on return types and fields; done means formatting preserves the annotation placement instead of splitting it from the type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.