iOS for loop breaks on substring exception inside a try-catch block

28 views
Skip to first unread message

Ulises Escobar

unread,
Jul 19, 2016, 3:47:54 PM7/19/16
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
OS: iOS
Device: iPhone 4 (ios 7.1.2), iPhone 5 (ios 9.3.2)
CN1 version: 3.4.3

I found a very rare bug in ios, when an exception occurs when trying to get a substring of an empty string inside a for loop, even when this code is inside a try-catch block, the system breaks the loop. Here is the code to reproduce it:

    String[] names = {"Ulises", "John", "", "Alexis", "Willy"}; 
    String resultStr = "";
    for (int i = 0; i < names.length; i++){
        try{
            String firstChar = names[i].substring(0, 1);
            resultStr += firstChar;
        }catch(Exception ex){
            Dialog.show("Error Dialog", "This dialog will show but the for statment should not have to break", "ok", "cancel");
        }
    }
    Dialog.show("Result Dialog", resultStr, "ok", "cancel");

The result string should be "UJAW" but in iOS the result string is "UJ".

I have already submited the issue #1834

Shai Almog

unread,
Jul 20, 2016, 1:27:18 AM7/20/16
to CodenameOne Discussions
This seems to be related to exception control flow. We had reports on this in the past but didn't have a good test case. Thanks.
Message has been deleted

Dave Dyer

unread,
Jul 22, 2016, 4:48:09 PM7/22/16
to CodenameOne Discussions
I call your attention to my report that catch/throw can cause stack corruption on IOS.

https://github.com/codenameone/CodenameOne/issues/1701

includes a test case

Shai Almog

unread,
Jul 23, 2016, 1:05:17 AM7/23/16
to CodenameOne Discussions
We have over 300 open issues with myself getting over 300 emails to process every day and that doesn't begin to describe the level of tasks...
I call to your attention the fact that you used a ZIP which I explained, again and again to you... Doesn't scale!

I looked at your issue and it went into the pile of "well I'll test it later". Later is a date that literally never happens.

Here I can instantly see that this test case is good, so it goes into the pile of "I need to schedule this".

We would have gotten to your issue even with the zip if we would have gotten repeated complaints especially referencing that issue. But if you want an issue addressed it needs to be scheduled and things won't get scheduled if we can't do quick evaluations of them.

Dave Dyer

unread,
Jul 24, 2016, 5:26:14 PM7/24/16
to CodenameOne Discussions

I try not to nag about the problems for which I have a satisfactory work around, but I did say in a thread here at the time
that stack corruption ought to be a 5-alarm fire.  I also expect this might be really hard to fix.

I do appreciate that you're balancing a lot of competing demands.

Shai Almog

unread,
Jul 24, 2016, 11:51:47 PM7/24/16
to CodenameOne Discussions
This is the second complaint on this issue in quite a long duration. We got more complaints about other VM issues such as date & time bugs etc.
Reply all
Reply to author
Forward
0 new messages