java: helper method for Kotlin
java: minor optimization
 fix thread crash in debug console after syntax error (PY-12600)

(cherry picked from commit 9cae29ece1f45b4e62ed2fe6ef1ea14c61d567eb)
Merge remote-tracking branch 'origin/master'