diff --git a/cql3/error_collector.hh b/cql3/error_collector.hh index 9a49714c78..2a83d6e042 100644 --- a/cql3/error_collector.hh +++ b/cql3/error_collector.hh @@ -67,6 +67,12 @@ class error_collector : public error_listener */ const sstring_view _query; + /** + * An empty bitset to be used as a workaround for AntLR null dereference + * bug. + */ + static typename ExceptionBaseType::BitsetListType _empty_bit_list; + public: /** @@ -144,6 +150,14 @@ private: break; } default: + // AntLR Exception class has a bug of dereferencing a null + // pointer in the displayRecognitionError. The following + // if statement makes sure it will not be null before the + // call to that function (displayRecognitionError). + // bug reference: https://github.com/antlr/antlr3/issues/191 + if (!ex->get_expectingSet()) { + ex->set_expectingSet(&_empty_bit_list); + } ex->displayRecognitionError(token_names, msg); } return msg.str(); @@ -345,4 +359,8 @@ private: #endif }; +template +typename ExceptionBaseType::BitsetListType +error_collector::_empty_bit_list = typename ExceptionBaseType::BitsetListType(); + }