LPS-40872 Reuse getSession(boolean) method

We should avoid returning a null wrapped around because this can prevent
API clients from performing null checks.
LPS-40872 Reuse getSession(boolean)... merge
LPS-41084 When possible, create regex pattern once and reuse instead of creating multiple times
LPS-41084 Use static pattern matcher (only the test part)
LPS-40716
LPS-40716