Split, replace, etc not working in lambda

I have a string of filenames separated by new line and want to replace the filenames by their names without extension.

var strNames = strFileNames.split('\n').map[string e | e.split(".jpg").get(0)]
logInfo(rulename, "strNames: {}", strNames)
  results in this error message:
strNames: [FAILED toString()]

Extensions like split, replace, substring do not seem to be accepted inside lambda.
What am I doing wrong?

The error is coming from the logInfo, not the map. The map is most likely just fine. The error is attempting to convert the java.util.List (which is what strNames is) to a String.

That should work too but Rules DSL messes with things sometimes. Try explicitly calling toString on strNames in the logInfo.

1 Like

Now I fooled myself entirely. When writing new rules I always check after each line the result. But a debug info that unnecassarily creates trouble happened to me the first time :slight_smile:
Thanks also for you explanation Rich.

The above code is still not working. Just to provide the correct code here, in case somebody else falls into this trap:
You may not declare the lambda variable as a String variable

var strNames = strFileNames.split('\n').map[e | e.split(".jpg").get(0)]