Converting from scala to java DSL something wrong with findAll

Hi gatling experts,
I’ve been using gatling for a while using the scala DSL but with 3.7 version i decided to give a try to the java DSL since to be honest I’ve always struggled a bit with scala…
So I’ve taken a project and I’ve tried to convert it using java DSL. I’m still testing if everything work fine, at the moment I found a strange difference on one check that was using css findAll function. Here was the original scala syntax for the check:

def selectProductCode(): HttpCheck = {
css(“input[name=‘productCodePost’]”, “value”).findAll.transform(random).optional.saveAs(“productCode”)
}

and the custom random function was:
val random = (list: Seq[String]) => {
list(Random.nextInt(list.size))

}

This is how I translated using the java DSL
public static final CheckBuilder.Final selectProductCode() {

return css(“input[name=‘productCodePost’]”, “value”).findAll().transform(random).optional().saveAs(“productCode”);
}

and the random function is:
private static Function<List, String> random = (final List list) → list.get(ThreadLocalRandom.current().nextInt(list.size()));

Now, I’ve notice that when the css selector find some occurrences the translated version works fine as the original one, but instead if the css selector has no match then the check break with this exception:

19:44:00.243 [DEBUG] i.g.h.e.r.DefaultStatsProcessor - Request ‘product detail page - pdpTypeAJAX’ failed for user 1: css((input[name=‘productCodePost’],Some(value))).findAll.transform.transformOption.noop extraction crashed: j.l.NullPointerException

I don’t know exactly if the NPE is issued in my custom “random” function and I should provide a check to avoid it or if the transform should not even call the function since findAll has retrieved no occurrences and in fact there’s the optional call after the transform step to save the value on the session only if present.

Has anyone faced the same issue with java DSL?

Thanks a lot