What if taskName is still empty?  taskName.length()-1 gives index -1.
"java.lang.StringIndexOutOfBoundsException: String index out of range: -1"