Hi Kaz,
Regarding the StackOverflowError: I also experienced those in combination with expensive regular expressions. The JVM stack size is quiet small per default (only 1MB), and so regular expressions can easily lead to a StackOverflowError.
Invoke Java with "-Xss2m", and it might already solve your problem.
Best,
Immanuel