# Gatling 2 - master - foreach crashes

**URL:** <https://community.gatling.io/t/gatling-2-master-foreach-crashes/398>\
**Category:** Gatling (Open-Source)\
**Created:** [May 29, 2013, 9:14am UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398 "2013-05-29T09:14:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Magnus\_Landro](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@Stefan\_Magnus\_Landro](https://community.gatling.io/u/Stefan_Magnus_Landro)\
**Post date:** [May 29, 2013, 9:14am UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/1 "2013-05-29T09:14:29Z")

</div>

Hi there,

I’m trying to use a foreach block in my scenario.

I’ve tried both alternatives (both crash):

.foreach("${ids}", “id”, “counter”) {  
exec(…)  
}

.foreach("${ids}", “id”) {  
exec(…)  
}

However, the repeat block works as expected

It crashes, due to what seems to be an error in Loops.scala:

def counterValue(implicit counterName: CounterName) = session(counterName.name).asInstanceOf[Int]

Stacktrace from simulation

java.lang.ClassCastException: io.gatling.core.session.SessionAttribute cannot be cast to java.lang.Integer  
at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)  
at io.gatling.core.structure.Loops$SessionCounters$.counterValue$extension(Loops.scala:39)  
at io.gatling.core.structure.Loops$$anonfun$6$$anonfun$apply$3.apply(Loops.scala:84)  
at io.gatling.core.structure.Loops$$anonfun$6$$anonfun$apply$3.apply(Loops.scala:84)

---

<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:** [May 29, 2013, 9:32am UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/2 "2013-05-29T09:32:24Z")

</div>

Hi Stefan,

Fixed, thanks!

---

<div class="post-metadata">

**Author:** ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)\
**Post date:** [April 9, 2014, 9:59am UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/3 "2014-04-09T09:59:37Z")

</div>

I habe a similar problem with Gatling 2.0.0M3a  
The body of foreach is executed in the correct way, but afterwards the following exception occurs

[ERROR] [04/09/2014 11:46:23.697] [GatlingSystem-akka.actor.default-dispatcher-3] [akka://GatlingSystem/user/$c/$a] tail of empty list

java.lang.UnsupportedOperationException: tail of empty list

at scala.collection.immutable.Nil$.tail(List.scala:339)

at scala.collection.immutable.Nil$.tail(List.scala:334)

at io.gatling.core.session.Session.exitInterruptable(Session.scala:105)

at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:54)

at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:54)

at io.gatling.core.action.InnerWhile.execute(While.scala:68)

at io.gatling.core.action.Action$$anonfun$receive$1.applyOrElse(Action.scala:27)

at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)

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

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

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

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

at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)

at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)

at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)

at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

11:46:23.712 [ERROR] i.g.c.a.InnerWhile - Action InnerWhile crashed, forwarding user to next one

java.lang.UnsupportedOperationException: tail of empty list

at scala.collection.immutable.Nil$.tail(List.scala:339) ~[na:na]

at scala.collection.immutable.Nil$.tail(List.scala:334) ~[na:na]

at io.gatling.core.session.Session.exitInterruptable(Session.scala:105) ~[gatling-core-2.0.0.20130628.jar:na]

at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:54) ~[gatling-core-2.0.0.20130628.jar:na]

at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:54) ~[gatling-core-2.0.0.20130628.jar:na]

at io.gatling.core.action.InnerWhile.execute(While.scala:68) ~[gatling-core-2.0.0.20130628.jar:na]

at io.gatling.core.action.Action$$anonfun$receive$1.applyOrElse(Action.scala:27) ~[gatling-core-2.0.0.20130628.jar:na]

at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) ~[akka-actor\_2.10-2.1.4.jar:na]

at akka.actor.ActorCell.invoke(ActorCell.scala:386) ~[akka-actor\_2.10-2.1.4.jar:na]

at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230) ~[akka-actor\_2.10-2.1.4.jar:na]

at akka.dispatch.Mailbox.run(Mailbox.scala:212) ~[akka-actor\_2.10-2.1.4.jar:na]

at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:506) [akka-actor\_2.10-2.1.4.jar:na]

at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [na:na]

at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [na:na]

at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [na:na]

at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [na:na]

– Ulrich

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [April 9, 2014, 10:31am UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/4 "2014-04-09T10:31:21Z")

</div>

Hi,

What does your scenario looks like?

I tried with :

scenario(“Debug test”)

.exec(\_.set(“ids”, List(1,2,3)))  
.foreach("${ids}", “id”) {  
exec(http(“with id”).get("/hello?id=$id"))  
}

but on the SNAPSHOT version, I can’t reproduce.

cheers  
Nicolas

---

<div class="post-metadata">

**Author:** ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)\
**Post date:** [April 9, 2014, 1:10pm UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/5 "2014-04-09T13:10:28Z")

</div>

Hi Nicolas,  
i constructed the following simplified scenario which runs and results in the same exception

[ERROR] [04/09/2014 15:04:40.353] [GatlingSystem-akka.actor.default-dispatcher-10] [akka://GatlingSystem/user/$b/$a] tail of empty list

class DummySimulation extends Simulation {

val headers= Map(

…

“Accept” → “application/json”,

“Content-Type” → “application/json; charset=utf-8”)

val httpProtocol= http.baseURL(“https://…”)

val scn = scenario(“get profile”)

.exec(\_.set(“ids”,List(“C9C21AF3-C8B4-456C-8CB8-083A566B0434”, “C9C21AF3-C8B4-456C-8CB8-083A566B0434”)))

.foreach("${ids}",“id”){

exec(

http(“test”)

.get("/test")

.headers(headers)

.header(“TEST-UID”,"${id}")

.check(status.saveAs(“status”), status.in(Seq(200,404)))

)}

setUp(

scn.inject(constantRate(1 usersPerSec) during (1 seconds)))

.protocols(httpProtocol)

}

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [April 9, 2014, 2:57pm UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/6 "2014-04-09T14:57:14Z")

</div>

Just tested on master, everything works fine.  
Given the fact that we will release soon, you should rather move to a SNAPSHOT version.

scenario I used:

package nico

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import io.gatling.jdbc.Predef.\_

import scala.concurrent.duration.\_

import scala.language.postfixOps

class DummySimulation extends Simulation {

val headers = Map(  
“Accept” → “application/json”,  
“Content-Type” → “application/json; charset=utf-8”)

val httpProtocol = http.baseURL(“[http://localhost:5000](http://localhost:5000)”).disableWarmUp

val scn = scenario(“get profile”)  
.exec(\_.set(“ids”, List(“C9C21AF3-C8B4-456C-8CB8-083A566B0434”, “C9C21AF3-C8B4-456C-8CB8-083A566B0434”)))  
.foreach("${ids}", “id”) {  
exec(  
http(“test”)  
.get("/")  
.headers(headers)  
.header(“TEST-UID”, “${id}”)  
.check(status.saveAs(“status”), [status.in](http://status.in)(Seq(200, 404))))  
}

setUp(  
scn.inject(constantUsersPerSec(1) during (1 seconds)))  
.protocols(httpProtocol)  
}

---

<div class="post-metadata">

**Author:** ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)\
**Post date:** [April 9, 2014, 3:47pm UTC](https://community.gatling.io/t/gatling-2-master-foreach-crashes/398/7 "2014-04-09T15:47:20Z")

</div>

Thanks,  
btw: what does soon mean? 😉
