trying figure out problem 2 weeks, without success. :x
it's occurring when i'm doing kind of iteration, when using #foreach.
i'm not modifying list, nor it's elements, in way, seems awkward me. example code:
map<season, list<team>> map = fetcher.getteamsin(ids); set<team> tocreateteams = new hashset<>(); set<team> toupdateteams = new hashset<>(); map.foreach((k, v) -> { tocreateteams.addall(v.stream().filter(t -> !persistedteams.containskey(t.getid())).collect(collectors.toset())); toupdateteams.addall(v.stream().filter(t -> { date latestpersistedupdate = persistedteams.get(t.getid()); return latestpersistedupdate != null && t.getlastupdated().after(latestpersistedupdate); }).collect(collectors.toset())); });
map instantiated in #getteamsin new hashmap<>();
tried break on exception in eclipse see if thread doing crazy shit, seems pretty normal me. in pics below, exception throw while iterating map
.
i started having other strange behaviours too, getting stuck in lambda expression forever. in case, seems me eclipse stopping in expression (for unknown reason), if breakpoint set in line. when suspend execution , resume problematic thread flow backs normal (until next lambda expression) or crazy concurrentmodificationexception.
the whole thing seems eclipse crazy bug me, don't want rebuild environment, if that's case.
i'm using
java(tm) se runtime environment (build 1.8.0_45-b14) java hotspot(tm) 64-bit server vm (build 25.45-b02, mixed mode)
on linux mint.
thanks!
-- update 1 --
just clear: error occurring simple example:
map.foreach((k, v) -> { system.out.println("test" + k.getid()); });
some random info might important: exception exploded after printing last element of map!
-- update 2 --
regarding random info in update 1, that's unimportant, since, performance reasons (at least in hashmap , arraylist), concurrentmodificationexception
checked in end of iterations, comparing actual size of array of elements expected size of it.
the code of method #getteamsin:
public map<season, list<team>> getteamsin(list<season> seasons) throws interruptedexception { final countdownlatch latch = new countdownlatch(seasons.size()); map<season, list<team>> teamsinseason = new hashmap<>(); (season s : seasons) { httpclient.execute(new httpget(string.format(url, s.getid())), new callback(latch) { @override public void completed(final httpresponse response) { super.completed(response); try { teamsinseason.put(s, new teamsunmarshaller().unmarshal(response.getentity().getcontent())); } catch (illegalstateexception | ioexception e) { // todo auto-generated catch block system.out.println(e); } } }); } latch.await(); return teamsinseason; }
callback
class implements futurecallback<httpresponse>
, countdown()
latch
in callback methods (#cancelled, #completed , #failed).
ok, found out problem. overrided #completed method in method #getteamsin taking long (thanks jaxb) return. since countdown()
(being called in super.completed(response)
) before teamsinseason.put(s, new teamsunmarshaller().unmarshal(response.getentity().getcontent()));
, have problem.
the fix simple , ugly:
@override public void completed(final httpresponse response) { try { teamsinseason.put(s, new teamsunmarshaller().unmarshal(response.getentity().getcontent())); } catch (illegalstateexception | ioexception e) { // todo auto-generated catch block system.out.println(e); } { super.completed(response); } }
the weird eclipse behaviour (getting stuck in imaginary breakpoint unknown reason), if persists, problem topic, think.
thank , time!