#2775 ConcurrentMap throws NotImmutableErr when trying to add array

beatfreaker Sun 3 Nov 2019

When i try to store array as value in ConcurrentMap, fantom is throwing sys::NotImmutableErr error.

Am i doing something wrong ?

using concurrent;

class MainTest {
    static Void main(Str[] args) {
        ConcurrentMap m := ConcurrentMap();
        m.add("1", ["a"]);		
    }
}

When i am executing above code it is throwing below error

sys::NotImmutableErr
  concurrent::ConcurrentMap.checkImmutable (ConcurrentMap.java:110)
  concurrent::ConcurrentMap.add (ConcurrentMap.java:39)
  bassgBacnetServer::MainTest.main (MainTest.fan:19)
  java.lang.reflect.Method.invoke (Unknown)
  fan.sys.Method.invoke (Method.java:573)
  fan.sys.Method$MethodFunc.callList (Method.java:212)
  fan.sys.Method.callList (Method.java:138)
  fanx.tools.Fan.callMain (Fan.java:183)
  fanx.tools.Fan.executeType (Fan.java:147)
  fanx.tools.Fan.execute (Fan.java:41)
  fanx.tools.Fan.run (Fan.java:308)
  fanx.tools.Fan.main (Fan.java:346)

beatfreaker Sun 3 Nov 2019

My bad, as ConcurrentMap is immutable we have to pass immutable data only.

I was able to make it work with below code.

ConcurrentMap m := ConcurrentMap();
m.add("1", ["a"].toImmutable)

Login or Signup to reply.