JBIDE-13938 Fixed and refactored error check