JDK-8043977 : Default encoding error when executing a jar file from the finder/desktop.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 7u55
  • Priority: P4
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-05-26
  • Updated: 2014-06-30
  • Resolved: 2014-06-30
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin Mac-mini-de-Oscar.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
The following example works fine if you execute it from command line, but if you create a jar and you execute the jar making double click it in the finder/desktop, you will see '?' chars instead of acuted vocals and n tilde.

This provokes different behaviour between developer execution (command line) and production execution (icon/app double click) in Mac OS X.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the example:

    javac DefaultEncoding.java

Create a jar file:

    jar cvfe DefaultEncoding.jar DefaultEncoding DefaultEncoding.class

Execute the jar file making double click it in the finder/desktop.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Message dialog showing in the last line:  ���� ���� ���� ���� ���� ����


ACTUAL -
Message dialog showing in the last line:  ? ? ? ? ? ?


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import javax.swing.*;

public class DefaultEncoding
{
    public static void main(String args[]) throws Exception
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream p = new PrintStream(baos);
        p.println("'aeiou' acutes and 'n' tilde:");
        p.println("\u00e1 \u00e9 \u00ed \u00f3 \u00fa \u00f1");
        p.close();
        JOptionPane.showMessageDialog(null, baos.toString());
        System.exit(0);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
You can specify a encoding in all cases, but you must catch UnsupportedEncodingException. This should be unnecessary.


Comments
Jar/class files are launched from the Desktop/Finder with the Jar Launcher application, which is a part of Apple Computer's Java implementation.
30-06-2014

Need to check if it is related to JDK-8033134
24-06-2014

Looks like user gets a difference behaviour when running jar file from command line and the desktop. Suspect that JDK reads in different values for default locale. I haven't run this test on a mac yet.
26-05-2014