# String cannot be cast to scala.collection.immutable.List Error

**URL:** <https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205>\
**Category:** Gatling (Open-Source)\
**Created:** [July 23, 2014, 6:57pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205 "2014-07-23T18:57:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [July 23, 2014, 6:57pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/1 "2014-07-23T18:57:44Z")

</div>

Hello,  
I am pretty new here so please bear with me. I am extracting a number of eventids into a list and iterate over that list repeatedly to use a unique event id in the subsequent request. However, when I try to simulate this, I am getting a String cannot be cast to scala.collection.immutable.List error. Below is my code. Could you please point out where exactly is the mistake and what kind of array manipulation function could be used here.

.exec(http(“Home Page”)  
.get("/")  
.headers(headers\_1)  
.check(status.is(200))  
.check(regex("""‘eventLink’\shref=’/sales/(\d+)""").findAll.saveAs(""“sales\_event\_id”""))  
)

.repeat(4){  
exec((session: Session) =\> { // use a simple action  
val sales\_event\_id = session.getTypedAttributeList[String] // retrieve the eventid saved by the previous check  
session.setAttribute(“sales\_event\_id”, sales\_event\_id(math.max(rnd.nextInt(sales\_event\_id.length), 9))) // store in the session a eventid randomly picked  
})

.doIf( session =\> session.isAttributeDefined(“sales\_event\_id”))  
{  
exec(http(“EDP”)  
.get("/sales/${sales\_event\_id}")  
.headers(headers\_1)  
.check(status.is(200))  
)  
}  
}

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 23, 2014, 8:52pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/2 "2014-07-23T20:52:51Z")

</div>

Which version do you use?  
Does the problem occurs compile time, or runtime?  
Could you provide the full stacktrace please?

---

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [July 23, 2014, 9:42pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/3 "2014-07-23T21:42:41Z")

</div>

Thanks for getting back, Stephane. So Im using 1.5.4 and this error happens during runtime. Her eis the full stack trace

14:37:00.331 [INFO] c.e.e.g.h.a.HttpRequestAction - Sending Request ‘Home Page’: Scenario ‘Storefront Gatling’, UserId #1

14:37:00.459 [INFO] c.e.e.g.h.c.CacheHandling$ - Setting LastModified for url [https://abc.com:443](https://abc.com:443)

14:37:00.466 [INFO] c.e.e.g.h.a.HttpRequestAction - Sending Request ‘EDP’: Scenario ‘Storefront Gatling’, UserId #1

14:37:02.799 [INFO] c.e.e.g.h.c.CacheHandling$ - Setting LastModified for url [https://abc.com:443/sales/39395](https://abc.com:443/sales/39395)

[ERROR] [07/23/2014 14:37:02.802] [GatlingSystem-akka.actor.default-dispatcher-20] [akka://GatlingSystem/user/$Ib] java.lang.String cannot be cast to scala.collection.immutable.List

java.lang.ClassCastException: java.lang.String cannot be cast to scala.collection.immutable.List

at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:84)

at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:83)

at com.excilys.ebi.gatling.core.action.SimpleAction.execute(SimpleAction.scala:37)

at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:31)

at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:30)

at akka.actor.Actor$class.apply(Actor.scala:318)

at com.excilys.ebi.gatling.core.action.SimpleAction.apply(SimpleAction.scala:29)

at akka.actor.ActorCell.invoke(ActorCell.scala:626)

at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)

at akka.dispatch.Mailbox.run(Mailbox.scala:179)

at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)

at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)

at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)

at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)

at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

14:37:03.488 [ERROR] c.e.e.g.c.a.SimpleAction - Action SimpleAction crashed, forwarding user to next one

java.lang.ClassCastException: java.lang.String cannot be cast to scala.collection.immutable.List

at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:84) ~[na:na]

at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:83) ~[na:na]

at com.excilys.ebi.gatling.core.action.SimpleAction.execute(SimpleAction.scala:37) ~[gatling-core-1.5.4.jar:na]

at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:31) ~[gatling-core-1.5.4.jar:na]

at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:30) ~[gatling-core-1.5.4.jar:na]

at akka.actor.Actor$class.apply(Actor.scala:318) ~[akka-actor-2.0.4.jar:2.0.4]

at com.excilys.ebi.gatling.core.action.SimpleAction.apply(SimpleAction.scala:29) ~[gatling-core-1.5.4.jar:na]

at akka.actor.ActorCell.invoke(ActorCell.scala:626) ~[akka-actor-2.0.4.jar:2.0.4]

at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) ~[akka-actor-2.0.4.jar:2.0.4]

at akka.dispatch.Mailbox.run(Mailbox.scala:179) ~[akka-actor-2.0.4.jar:2.0.4]

at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor-2.0.4.jar:2.0.4]

at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor-2.0.4.jar:2.0.4]

at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor-2.0.4.jar:2.0.4]

at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor-2.0.4.jar:2.0.4]

at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor-2.0.4.jar:2.0.4]

14:37:03.488 [INFO] c.e.e.g.h.a.HttpRequestAction - Sending Request ‘EDP’: Scenario ‘Storefront Gatling’, UserId #1

14:37:03.704 [WARN] c.e.e.g.h.a.GatlingAsyncHandlerActor - Request ‘EDP’ failed : Check ‘is’ failed, found 304 but expected 200

14:37:03.712 [DEBUG] c.e.e.g.h.a.GatlingAsyncHandlerActor -

> > > > > > > > > > > > > > > > > > > > > > > > > >

Request:

EDP: KO Check ‘is’ failed, found 304 but expected 200

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 24, 2014, 6:15am UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/4 "2014-07-24T06:15:27Z")

</div>

This doesn’t make sense?!  
Are you sure that you’re not using “sales\_event\_id” for storing a single String before that?

---

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [August 7, 2014, 11:13pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/5 "2014-08-07T23:13:22Z")

</div>

Nope. This is the first time I am using a sales\_event\_id variable and my intention is to capture a list of event\_ids here. Just for your review, Here is my complete script.

package storefront  
import com.excilys.ebi.gatling.core.Predef.\_  
import com.excilys.ebi.gatling.http.Predef.\_  
import StorefrontHeaders.\_  
import akka.util.duration.\_  
import bootstrap.\_  
import scala.util.\_  
import scala.util.Random

object pod1Scenario {

// val r = scala.util.Random  
// var x = r.nextInt(20)  
val testTimeSecs = 1800  
val minWaitMs = 10000 milliseconds  
val maxWaitMs = 30000 milliseconds  
val rnd = new scala.util.Random  
val range = 1 to 20  
val id = (range(rnd.nextInt(range length)))

val scn = scenario(“Storefront Pod1”)

.during(testTimeSecs) {

pauseExp(15 seconds)  
.exec(http(“XX\_LoginPage”)  
.get("/login")  
.headers(headers\_1)  
)  
.pause(minWaitMs, maxWaitMs)

.feed(csv(“storefront\_users.csv”).random)

.pause(minWaitMs, maxWaitMs)

// RAILS Login Request

.exec(http(“XX\_LoginPOST”)  
.post("/customers/sign-in.json")  
.headers(headers\_23)  
.param(""“email”"", “${username}”)  
.param(""“password”"", “${password}”)  
.param(""“keepLogIn”"", “”“0"”")  
.param(""“applicationType”"", “”“storefront”"")  
.param(""“format”"", “”“json”""))  
// RAILS Login Request

.repeat(4){  
pause(minWaitMs, maxWaitMs)  
exec(http(“Home Page”)  
.get(“[https://abc.com/homepage](https://abc.com/homepage)”)  
.headers(headers\_1)  
.check(status.is(200))  
.check(regex("""‘eventLink’\shref=’/sales/(\d+)""").findAll.saveAs(""“sales\_event\_id”""))  
)}

.exec((session: Session) =\> { // use a simple action  
val sales\_event\_id = session.getTypedAttributeList[String] // retrieve the keywords saved by the previous check  
session.setAttribute(“sales\_event\_id”, sales\_event\_id(math.max(rnd.nextInt(sales\_event\_id.length), 9))) // store in the session a keywork randomly picked  
})

.pause(minWaitMs, maxWaitMs)

.doIf( session =\> session.isAttributeDefined(“sales\_event\_id”))  
{  
repeat(13){  
pause(minWaitMs, maxWaitMs)  
exec(http(“XX\_EDP”)  
.get("/sales/${sales\_event\_id}")  
.headers(headers\_1)  
.check(status.is(200))  
.check(regex(""“data-product-id=’(\d+)”"").find(id).exists.saveAs(""“product\_id”""))  
)  
}}

.exec(http(“XX\_To\_Retrieve\_SKU”)  
.get("/product/${sales\_event\_id}/${product\_id}")  
.headers(headers\_1)  
// .check(status.is(200))  
.check(regex("""“id”:(\d+),“quantity”:[1-9]\*[0-9],“reservable\_quantity”:\d+,“on\_hold”:false,“price”:""").find(0).exists.saveAs(""“sku\_id”""))  
)

.pause(minWaitMs, maxWaitMs)

.doIf( session =\> session.isAttributeDefined(“product\_id”))  
{  
repeat(13){  
pause(minWaitMs, maxWaitMs)  
exec(http(“XX\_PDP Storefront”)  
.get("/product/${sales\_event\_id}/${product\_id}")  
.headers(headers\_1)  
.check(status.is(200))  
// .check(regex("""‘selectSkuId’\sname=‘skuId’\stype=‘hidden’\svalue=’(\d+)’\>""").find.exists.saveAs(""“sku\_id”""))  
// .check(regex("""\<input\sid=‘selectSkuId’\sname=‘skuId’\stype=‘hidden’\svalue=’(\d+)""").find(0).exists.saveAs(""“sku\_id”""))  
//check to see if a product is sold out. If yes, then dont add to cart  
// .check(regex("""\<button class=‘addToCart trackAddToCart’ type=‘submit’\>Add To Cart\</button\>""").find.exists.saveAs(""“available”""))

)  
} }

.exec(http(“XX\_Logout”)  
.get("/logout")  
.headers(headers\_1)  
)

}  
}

---

<div class="post-metadata">

**Author:** ![Michelle\_Burrows](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Michelle\_Burrows](https://community.gatling.io/u/Michelle_Burrows)\
**Post date:** [August 8, 2014, 12:16pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/6 "2014-08-08T12:16:29Z")

</div>

You have two very different snippets of code posted, now. Did you change your code (and are you getting the same error in the same place?), or is it a copy/paste error (and which one is actually correct)? I could tell you exactly what’s going wrong with your first piece of code (where the repeat() is around the session function) - on the first iteration, it was setting the sales\_event\_id attribute to a single element of the list (a string), and then trying to get that string as a list on the second iteration.

---

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [August 8, 2014, 11:53pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/7 "2014-08-08T23:53:56Z")

</div>

Thanks for the reply, Michelle. Sorry about the second code - it is my old code. I understand your explanation about my original snippet. So could you please tell me how do I extract dynamic valuse from the list ‘sales\_event\_id’ and use it in the subsequent requests. I also tried the loop{chain} from this example [https://gist.github.com/slandelle/2469375](https://gist.github.com/slandelle/2469375), but not much luck there. Getting an error- value loop is not a member of com.excilys.ebi.gatling.core.structure.ChainBuilder’. Appreciate your time.

---

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [August 11, 2014, 9:11pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/8 "2014-08-11T21:11:38Z")

</div>

Hey Stephane,  
I also tried with the loop chain to iterate over the list that I have. Here is the code. However, during compilation I get an error stating that ‘value loop is not a member of com.excilys.ebi.gatling.core.structure.ChainBuilder’. Still wondering how to i iterate over a list of sales\_event\_ids that I extracted from the home page. Appreciate your time.

.exec(http(“Home Page”)  
.get(“[https://load01.newokl.com/homepage](https://load01.newokl.com/homepage)”)  
.headers(headers\_1)  
.check(regex(""“href=’/sales/(\d+)”"").findAll.saveAs(""“sales\_event\_id”""))  
)

.loop(  
chain  
.exec((session: Session) =\> { // use a simple action  
val keywords = session.getTypedAttributeList[String] // retrieve the keywords saved by the previous check  
session.setAttribute(“sales\_event\_id”, keywords(math.max(rnd.nextInt(sales\_event\_id.length), 9))) // store in the session a keywork randomly picked  
})  
.exec(http(“XX\_EDP”).get("/sales/${sales\_event\_id}")))  
.counterName(“eventidCounter”)  
.asLongAs((session: Session) =\> {  
val sales\_event\_id = session.getTypedAttributeList[String]  
session.getCounterValue(“eventidCounter”) \< math.max(sales\_event\_id.length, 10)  
})

---

<div class="post-metadata">

**Author:** ![Surekha\_Anantharaman](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Surekha\_Anantharaman](https://community.gatling.io/u/Surekha_Anantharaman)\
**Post date:** [August 11, 2014, 9:34pm UTC](https://community.gatling.io/t/string-cannot-be-cast-to-scala-collection-immutable-list-error/1205/9 "2014-08-11T21:34:01Z")

</div>

Never mind. I figured out how to do it. This piece worked.

.repeat(session =\> session.getTypedAttributeList[String].size, “loopIndex”) {  
exec(http(“XX\_EDP for product id”)  
.get("/sales/${sales\_event\_id(loopIndex)}"))  
}
