U+2212 Minus Sign "−".getBytes("Windows-31j") will return 3f, not 0x817c with OpenJDK

Solution Verified - Updated -

Issue

We are migrating from IBM JDK to OpenJDK, but the following code writes ?(0x3f) to test.txt with Red Hat OpenJDK. It can be converted to 0x817c with IBM JDK.

import java.io.File;
import java.io.FileOutputStream;

public class Main {
    public static void main(String[] args) throws Exception {
        String s = "−";   // U+2212 Minus Sign
        File f = new File("test.txt");
        FileOutputStream out = new FileOutputStream(f);
        out.write(s.getBytes("Windows-31j"));
    }
}

Environment

  • OpenJDK
    • 8, 11, 17, 21
  • IBM JDK
    • 7, 8

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content