-
Notifications
You must be signed in to change notification settings - Fork 917
Description
Apache NetBeans version
Apache NetBeans 16
What happened
This is almost the same issue as #3720.
When Java code is automatically formatting a try-with-resources statement, if the resource is specified with the type var instead of a specific type, an additional space is injected before the var keyword.
How to reproduce
With a clean install of NetBeans 16 on MacOS 13.1, with the default Java code formatting settings (no changes to defaults after install, and no importing of previous version settings), and using a "new file", and no existing project:
- Create a new Java file:
- Replace all code with the following:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class NewClass {
public void test() throws IOException {
try (var br = Files.newBufferedReader(Paths.get("test"))) {
}
}
}
- Select "Format" from the "Source" menu and the code will be reformatted as:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class NewClass {
public void test() throws IOException {
try ( var br = Files.newBufferedReader(Paths.get("test"))) {
}
}
}
Note the additional space in try ( var.
If you replace var with BufferedReader, the problem does not occur.
Did this work correctly in an earlier version?
Apache NetBeans 12.6 or earlier
Operating System
Mac OS X version 13.1 running on aarch64; UTF-8; en_CA (nb)
JDK
18.0.2; OpenJDK 64-Bit Server VM 18.0.2+9-FR
Apache NetBeans packaging
Apache NetBeans provided installer
Anything else
No response
Are you willing to submit a pull request?
No
Code of Conduct
Yes