wei-spring / codenameone

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

error iterating over a TreeSet #1287

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
TreeSet<String> anni = new TreeSet<String>();
for(String s : files){ //files is a String[]
    try{
        String sub = s.substring(0, 4);
        Integer.parseInt(sub);
        years.add(sub);
    }catch(NumberFormatException nfe){

    }
}
for(String s : years){
    v.add(new ReportBranch(null, s));
}

What is the expected output?
iterate a TreeSet to fill a Vector

What do you see instead?
Xcode error:
"IJobClock(19931,0xb0103000) malloc: *** error for object 0x7f5fb044: incorrect 
checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug"

What version of the product are you using?
iPod 4th gen
IPhone 6 emulator

On what operating system?
iOS 6.1
iOS 8.1

Original issue reported on code.google.com by rbry...@gmail.com on 14 Jan 2015 at 7:37

GoogleCodeExporter commented 9 years ago
this happen with iOS.newVM=true

Original comment by rbry...@gmail.com on 14 Jan 2015 at 8:08

GoogleCodeExporter commented 9 years ago
We made improvements to the GC which should hopefully fix that

Original comment by shai.almog on 18 Jan 2015 at 2:10

GoogleCodeExporter commented 9 years ago
hi shai,
my app still crash, I didn't check well if the error is the same but the 
procedure is the same.

Original comment by rbry...@gmail.com on 28 Jan 2015 at 6:29

GoogleCodeExporter commented 9 years ago
Try using the TreeSet constructor that takes a comparator as one of the 
parameters.  (And, of course implement a Comparator the does the comparison).  
Let me know if that works.  I think I know what may be happening here.

Original comment by st...@weblite.ca on 28 Jan 2015 at 11:55

GoogleCodeExporter commented 9 years ago
Just tried running this test case and it fails with the same error.  Screenshot 
attached or Xcode stack and error.

Running through a few things.  Likely a GC problem though.

Original comment by steve.ha...@codenameone.com on 30 Jan 2015 at 10:16

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by steve.ha...@codenameone.com on 30 Jan 2015 at 10:20

GoogleCodeExporter commented 9 years ago
Also I note that changing to providing explicit comparator for treeset makes no 
difference.  My test case is attached.

Original comment by steve.ha...@codenameone.com on 30 Jan 2015 at 10:23

Attachments:

GoogleCodeExporter commented 9 years ago
thank you steve, I didn't have the time to do these checks by myself, I'm 
sorry...

Original comment by rbry...@gmail.com on 30 Jan 2015 at 11:36

GoogleCodeExporter commented 9 years ago
I just tried Steve's test case on my device and it works fine. No idea what 
sort of crash you are still seeing.

Original comment by shai.almog on 31 Jan 2015 at 11:34

GoogleCodeExporter commented 9 years ago
After updating to the latest changes this morning, my test case (with the 
Comparator in the constructor of TreeSet) now passes.  If I use the default 
constructor, I still get the same error.

I suspect this may be related to the fact that String doesn't implement 
Comparable in the NewVM's JavaAPI.  I have already created workarounds for all 
of the Number classes.  I'll look into this more on Monday to see if I need to 
do something similar with Strings.

Attached is a new test case (without the Comparator in the constructor).

Original comment by steve.ha...@codenameone.com on 31 Jan 2015 at 2:03

Attachments:

GoogleCodeExporter commented 9 years ago
I'll just make String implement comparable.

Original comment by shai.almog on 31 Jan 2015 at 3:53

GoogleCodeExporter commented 9 years ago
It would be interesting to see if this works on J2ME as their String class 
doesn't implement Comparable either.  My guess is that it will throw a 
ClassCastException.

Original comment by steve.ha...@codenameone.com on 31 Jan 2015 at 4:50

GoogleCodeExporter commented 9 years ago
sorry for the delay but is a busy period.
Unfortunately I still have problems with TreeSet. Just to be sure I tried to 
build a new form with a Tree that shows integer as branch ending with leaf 
having 4 digits: all was ok until I used a TreeSet<Integer> to collect children 
values before transferring them to a Vector<Integer>. I tried to notify another 
issue but it has been refused by shai saying that it is a VM break down.

As you can see it is not a matter of String because Integer lead to the same 
result.

Try to use the attached BuggyTreeForm.

Please, I'm near to publish for iOS, they just disapproved my binary because of 
oldVM(which runs perfectly) being only 32bit.

Original comment by rbry...@gmail.com on 1 Mar 2015 at 1:11

Attachments:

GoogleCodeExporter commented 9 years ago
I just built your test case and ran it on iPhone 4S/8.1, and it runs fine, so 
I'm guessing Shai already fixed this.

Original comment by st...@weblite.ca on 2 Mar 2015 at 4:31

GoogleCodeExporter commented 9 years ago
Yes, I got a good test case today and committed a fix this morning. It seems 
that TreeSet implements a hierarchy of interfaces in a rather unique way that 
caused one of the interfaces in the hierarchy to map method offsets badly. 

Original comment by shai.almog on 2 Mar 2015 at 6:33