openGeeksLab / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

iOS newVM InputStream encoding problems #1285

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Device: iPad Air

Steps to reproduce:
1. create a file with UTF-8 encoding and letters with accents like 
ä,ö,ü,ß,á etc.
2. open the file via InputStream e.g 
Display.getInstance().getResourceAsStream(getClass(), "/special.json")
2.1 this also occurs if you try to read a response via ConnectionRequest
3. retrieve content of the InputStream e.g. Util.readToString(stream, "UTF-8");
4. create a Label and set the string as text

Output:
The compiled app displays [?] question marks and other symbols instead of the 
expected characters on an iOS device. 
The characters are displayed fine when running in the simulator, android and on 
iOS with newVM=false.

OS: Windows 7
Dev: Eclipse Kepler

Original issue reported on code.google.com by appsepp....@gmail.com on 14 Jan 2015 at 4:44

Attachments:

GoogleCodeExporter commented 8 years ago
The problems seams to be due to a bug in constructor String(byte[], String), 
for example this code:

        byte[] bytesData = {-62, -93, -30, -126, -84};
        try {
            final String result = new String(bytesData, "UTF-8");
            System.out.println("GOT: " + result);
            byte[] butNow = result.getBytes("UTF-8");
            for (int i = 0; i < butNow.length; i++) {
                System.out.println("[" + i + "] = " + butNow[i]);
            }

            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    Dialog.show("Result in UI", result, "Ok", null);
                }

            });
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }

prints out on simulator:

GOT: £€
[0] = -62
[1] = -93
[2] = -30
[3] = -126
[4] = -84

but the new iOS VM prints:

2015-01-16 13:44:00.090 MyApplication[55021:c03] GOT: ᅡᆪ¬ツᆲ
2015-01-16 13:44:00.092 MyApplication[55021:c03] [0] = -17
2015-01-16 13:44:00.093 MyApplication[55021:c03] [1] = -65
2015-01-16 13:44:00.094 MyApplication[55021:c03] [2] = -126
2015-01-16 13:44:00.095 MyApplication[55021:c03] [3] = -17
2015-01-16 13:44:00.096 MyApplication[55021:c03] [4] = -66
2015-01-16 13:44:00.097 MyApplication[55021:c03] [5] = -93
2015-01-16 13:44:00.098 MyApplication[55021:c03] [6] = -17
2015-01-16 13:44:00.099 MyApplication[55021:c03] [7] = -65
2015-01-16 13:44:00.100 MyApplication[55021:c03] [8] = -94
2015-01-16 13:44:00.101 MyApplication[55021:c03] [9] = -17
2015-01-16 13:44:00.102 MyApplication[55021:c03] [10] = -66
2015-01-16 13:44:00.103 MyApplication[55021:c03] [11] = -126
2015-01-16 13:44:00.103 MyApplication[55021:c03] [12] = -17
2015-01-16 13:44:00.104 MyApplication[55021:c03] [13] = -66
2015-01-16 13:44:00.105 MyApplication[55021:c03] [14] = -84

Original comment by jaanus.h...@gmail.com on 16 Jan 2015 at 11:50

GoogleCodeExporter commented 8 years ago
Thanks, this was triggered by a bug in an optimization for ascii characters 
which is now fixed.

Original comment by shai.almog on 20 Jan 2015 at 12:10