Fixes JPX COC support / JPX error reporting refactoring

Same as #4639 plus test case and error reporting refactoring.