apache / apache/netbeans

Output encoding in Windows uses cp-1252 by default instead of utf-8

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

Description

### Apache NetBeans version

Apache NetBeans 15

### What happened

If you try to output any text in UTF-8, it is not displayed correctly in Windows with JDK19, as it assumes the default of cp1252.

It works with JDK17.

### How to reproduce

Just create any project and output any special character that cp1252 and utf-8 encode differently.

```java
// Note that this assumes that your file is saved as utf-8, which is the default.
System.out.println("á");
System.out.println("\uD83D\uDC7D");
System.out.println("🌚");
System.out.println("\u4e16\u754c");
```

Displays:

```

?
?
??
```

### Did this work correctly in an earlier version?

Apache NetBeans 12.6

### Operating System

Windows 10, Windows 11. 64 bit

### JDK

JDK19

### Apache NetBeans packaging

Apache NetBeans provided installer

### Anything else

```java
System.out.println("Charset.defaultCharset(): " + Charset.defaultCharset());
System.out.println("file.encoding property:" + System.getProperty("file.encoding"));
System.out.println("native.encoding property:" + System.getProperty("native.encoding"));
System.out.println("sun.jnu.encoding property:" + System.getProperty("sun.jnu.encoding"));
System.out.println("stdout.encoding property:" + System.getProperty("stdout.encoding"));
System.out.println("sun.stdout.encoding property:" + System.getProperty("sun.stdout.encoding"));
```

Displays:

```
Charset.defaultCharset(): UTF-8
file.encoding property:UTF-8
native.encoding property:Cp1252
sun.jnu.encoding property:Cp1252
stdout.encoding property:Cp1252
sun.stdout.encoding property:null
```

**What did not work**
- Adding `-J-Dnative.encoding=utf-8 -J-Dstdout.encoding=utf-8 -J-Dsun.stdout.encoding=utf-8` in `netbeans_default_options` in `netbeans.conf`.

**Workarounds**
- You can set the `-Dstdout.encoding=utf-8` VM option in the project.
- You can reset the `System.out` to make it use utf-8: `System.setOut(new PrintStream(System.out, true, "UTF8"));`.

**What should happen**
- It should work straight out of the box.
- Or, at least, there should be a way to make utf-8 the default (setting something in `netbeans.conf`).

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

No

### Code of Conduct

Yes

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the sample Java output on Windows with JDK 19 and inspect how project execution handles System.out encoding, including the netbeans.conf options mentioned. Done means UTF-8 characters display correctly out of the box, or a documented netbeans.conf setting reliably selects UTF-8.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.