Program: 35302
Project: 35302
Buggy source:
/** 
 * Parses a portion of JSON from the given   {@code Bytes} from it's{@link net.openhft.lang.io.Bytes#position() position} to{@link net.openhft.lang.io.Bytes#limit() limit}. Position is incremented until there are no   {@link net.openhft.lang.io.Bytes#remaining() remaining} bytes or a single top-levelJSON object is parsed and  {@link JsonParserTopLevelStrategy#ALLOW_TRAILING_GARBAGE} is set.<p>As this is a pull parser, the given JSON text may break at any character. If the {@link net.openhft.saxophone.json.JsonParserOption#ALLOW_PARTIAL_VALUES} is not set,{@link net.openhft.saxophone.ParseException} will be thrown only on {@link #finish()} call.<p>As JSON tokens are parsed, appropriate event handlers are notified. To ensure that the last token is processed, call  {@link #finish()} afterwards.<p>Returns  {@code true} if the parsing succeed and token handlers haven't send a cancelrequest (i. e. returned  {@code true} all the way). If any handler returns {@code false}, parsing is terminated immediately and   {@code false} is returned.<p>If one of the handlers throws a checked exception, it is wrapped with {@link net.openhft.saxophone.ParseException} (and available through{@link net.openhft.saxophone.ParseException#getCause()} later). If one of the handlers throwsan unchecked exception ( {@link java.lang.RuntimeException}), it is rethrown without any processing.
 * @param jsonText a portion of JSON to parse
 * @return {@code true} if the parsing wasn't cancelled by handlers
 * @throws net.openhft.saxophone.ParseException if the given JSON is malformed (exact meaning of"malformed" depends on parser's  {@link JsonParserBuilder#options() options}), or if one of the handlers throws a checked exception, or   {@link net.openhft.saxophone.json.handler.IntegerHandler} is provided but parsedinteger value is out of primitive  {@code long} range:greater than  {@code Long.MAX_VALUE} or lesser than {@code Long.MIN_VALUE}
 * @throws IllegalStateException if parsing was cancelled or any exception was thrownin this method after the previous  {@link #reset()} call or parser construction
 */
public boolean parse(Bytes jsonText){
  TokenType tok;
  long startOffset=jsonText.position();
  around_again:   while (true) {
switch (stateStack.current()) {
case PARSE_COMPLETE:
      if (topLevelStrategy == ALLOW_MULTIPLE_VALUES) {
        stateStack.set(GOT_VALUE);
        continue around_again;
      }
    if (topLevelStrategy != ALLOW_TRAILING_GARBAGE) {
      if (jsonText.remaining() > 0) {
        tok=lexer.lex(jsonText);
        if (tok != EOF) {
          return parseError("String_Node_Str");
        }
        continue around_again;
      }
    }
  return true;
case LEXICAL_ERROR:
case PARSE_ERROR:
throw new IllegalStateException("String_Node_Str" + parseError);
case HANDLER_CANCEL:
throw new IllegalStateException("String_Node_Str");
case HANDLER_EXCEPTION:
throw new IllegalStateException("String_Node_Str");
case START:
case GOT_VALUE:
case MAP_NEED_VAL:
case ARRAY_NEED_VAL:
case ARRAY_START:
{
byte stateToPush=START;
tok=lexer.lex(jsonText);
switch (tok) {
case EOF:
return true;
case ERROR:
lexicalError();
case STRING:
if (stringValueHandler != null) {
try {
if (!onString.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case STRING_WITH_ESCAPES:
if (stringValueHandler != null) {
try {
if (!onEscapedString.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case BOOL:
if (booleanHandler != null) {
boolean value=lexer.outBuf.readUnsignedByte(lexer.outPos) == 't';
try {
if (!booleanHandler.onBoolean(value)) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case NULL:
if (nullHandler != null) {
try {
if (!nullHandler.onNull()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case LEFT_BRACKET:
if (objectStartHandler != null) {
try {
if (!objectStartHandler.onObjectStart()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateToPush=MAP_START;
break;
case LEFT_BRACE:
if (arrayStartHandler != null) {
try {
if (!arrayStartHandler.onArrayStart()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateToPush=ARRAY_START;
break;
case INTEGER:
if (numberHandler != null) {
if (stringValueHandler != null) {
try {
if (!onNumber.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
}
 else if (integerHandler != null) {
try {
long i=parseInteger(lexer.outBuf,lexer.outPos,lexer.outLen);
if (!integerHandler.onInteger(i)) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (NumberFormatException e) {
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str",e);
}
catch (Exception e) {
return handlerError(e);
}
}
break;
case DOUBLE:
if (numberHandler != null) {
if (stringValueHandler != null) {
try {
if (!onNumber.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
}
 else if (floatingHandler != null) {
try {
if (!onFloating.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (NumberFormatException e) {
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str",e);
}
catch (Exception e) {
return handlerError(e);
}
}
break;
case RIGHT_BRACE:
{
if (stateStack.current() == ARRAY_START) {
if (arrayEndHandler != null) {
try {
if (!arrayEndHandler.onArrayEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
}
}
case COLON:
case COMMA:
case RIGHT_BRACKET:
return parseError("String_Node_Str");
default :
return parseError("String_Node_Str");
}
{
byte s=stateStack.current();
if (s == START || s == GOT_VALUE) {
stateStack.set(PARSE_COMPLETE);
}
 else if (s == MAP_NEED_VAL) {
stateStack.set(MAP_GOT_VAL);
}
 else {
stateStack.set(ARRAY_GOT_VAL);
}
}
if (stateToPush != START) {
stateStack.push(stateToPush);
}
continue around_again;
}
case MAP_START:
case MAP_NEED_KEY:
{
tok=lexer.lex(jsonText);
OnString onKey=this.onKey;
switch (tok) {
case EOF:
return true;
case ERROR:
lexicalError();
case STRING_WITH_ESCAPES:
onKey=onEscapedKey;
case STRING:
if (objectKeyHandler != null) {
try {
if (!onKey.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.set(MAP_SEP);
continue around_again;
case RIGHT_BRACKET:
if (stateStack.current() == MAP_START) {
if (objectEndHandler != null) {
try {
if (!objectEndHandler.onObjectEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
}
default :
return parseError("String_Node_Str");
}
}
case MAP_SEP:
{
tok=lexer.lex(jsonText);
switch (tok) {
case COLON:
stateStack.set(MAP_NEED_VAL);
continue around_again;
case EOF:
return true;
case ERROR:
lexicalError();
default :
return parseError("String_Node_Str");
}
}
case MAP_GOT_VAL:
{
tok=lexer.lex(jsonText);
switch (tok) {
case RIGHT_BRACKET:
if (objectEndHandler != null) {
try {
if (!objectEndHandler.onObjectEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
case COMMA:
stateStack.set(MAP_NEED_KEY);
continue around_again;
case EOF:
return true;
case ERROR:
lexicalError();
default :
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str");
}
}
case ARRAY_GOT_VAL:
{
tok=lexer.lex(jsonText);
switch (tok) {
case RIGHT_BRACE:
if (arrayEndHandler != null) {
try {
if (!arrayEndHandler.onArrayEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
case COMMA:
stateStack.set(ARRAY_NEED_VAL);
continue around_again;
case EOF:
return true;
case ERROR:
return lexicalError();
default :
return parseError("String_Node_Str");
}
}
}
}
}

Fixed version (ground truth):
/** 
 * Parses a portion of JSON from the given   {@code Bytes} from it's{@link net.openhft.lang.io.Bytes#position() position} to{@link net.openhft.lang.io.Bytes#limit() limit}. Position is incremented until there are no   {@link net.openhft.lang.io.Bytes#remaining() remaining} bytes or a single top-levelJSON object is parsed and  {@link JsonParserTopLevelStrategy#ALLOW_TRAILING_GARBAGE} is set.<p>As this is a pull parser, the given JSON text may break at any character. If the {@link net.openhft.saxophone.json.JsonParserOption#ALLOW_PARTIAL_VALUES} is not set,{@link net.openhft.saxophone.ParseException} will be thrown only on {@link #finish()} call.<p>As JSON tokens are parsed, appropriate event handlers are notified. To ensure that the last token is processed, call  {@link #finish()} afterwards.<p>Returns  {@code true} if the parsing succeed and token handlers haven't send a cancelrequest (i. e. returned  {@code true} all the way). If any handler returns {@code false}, parsing is terminated immediately and   {@code false} is returned.<p>If one of the handlers throws a checked exception, it is wrapped with {@link net.openhft.saxophone.ParseException} (and available through{@link net.openhft.saxophone.ParseException#getCause()} later). If one of the handlers throwsan unchecked exception ( {@link java.lang.RuntimeException}), it is rethrown without any processing.
 * @param jsonText a portion of JSON to parse
 * @return {@code true} if the parsing wasn't cancelled by handlers
 * @throws net.openhft.saxophone.ParseException if the given JSON is malformed (exact meaning of"malformed" depends on parser's  {@link JsonParserBuilder#options() options}), or if one of the handlers throws a checked exception, or   {@link net.openhft.saxophone.json.handler.IntegerHandler} is provided but parsedinteger value is out of primitive  {@code long} range:greater than  {@code Long.MAX_VALUE} or lesser than {@code Long.MIN_VALUE}
 * @throws IllegalStateException if parsing was cancelled or any exception was thrownin this method after the previous  {@link #reset()} call or parser construction
 */
public boolean parse(Bytes jsonText){
  TokenType tok;
  long startOffset=jsonText.position();
  around_again:   while (true) {
switch (stateStack.current()) {
case PARSE_COMPLETE:
      if (topLevelStrategy == ALLOW_MULTIPLE_VALUES) {
        stateStack.set(GOT_VALUE);
        continue around_again;
      }
    if (topLevelStrategy != ALLOW_TRAILING_GARBAGE) {
      if (jsonText.remaining() > 0) {
        tok=lexer.lex(jsonText);
        if (tok != EOF) {
          return parseError("String_Node_Str");
        }
        continue around_again;
      }
    }
  return true;
case LEXICAL_ERROR:
case PARSE_ERROR:
throw new IllegalStateException("String_Node_Str" + parseError);
case HANDLER_CANCEL:
throw new IllegalStateException("String_Node_Str");
case HANDLER_EXCEPTION:
throw new IllegalStateException("String_Node_Str");
case START:
case GOT_VALUE:
case MAP_NEED_VAL:
case ARRAY_NEED_VAL:
case ARRAY_START:
{
byte stateToPush=START;
tok=lexer.lex(jsonText);
switch (tok) {
case EOF:
return true;
case ERROR:
lexicalError();
case STRING:
if (stringValueHandler != null) {
try {
if (!onString.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case STRING_WITH_ESCAPES:
if (stringValueHandler != null) {
try {
if (!onEscapedString.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case BOOL:
if (booleanHandler != null) {
boolean value=lexer.outBuf.readUnsignedByte(lexer.outPos) == 't';
try {
if (!booleanHandler.onBoolean(value)) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case NULL:
if (nullHandler != null) {
try {
if (!nullHandler.onNull()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
break;
case LEFT_BRACKET:
if (objectStartHandler != null) {
try {
if (!objectStartHandler.onObjectStart()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateToPush=MAP_START;
break;
case LEFT_BRACE:
if (arrayStartHandler != null) {
try {
if (!arrayStartHandler.onArrayStart()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateToPush=ARRAY_START;
break;
case INTEGER:
if (numberHandler != null) {
try {
if (!onNumber.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
 else if (integerHandler != null) {
try {
long i=parseInteger(lexer.outBuf,lexer.outPos,lexer.outLen);
if (!integerHandler.onInteger(i)) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (NumberFormatException e) {
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str",e);
}
catch (Exception e) {
return handlerError(e);
}
}
break;
case DOUBLE:
if (numberHandler != null) {
try {
if (!onNumber.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
 else if (floatingHandler != null) {
try {
if (!onFloating.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (NumberFormatException e) {
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str",e);
}
catch (Exception e) {
return handlerError(e);
}
}
break;
case RIGHT_BRACE:
{
if (stateStack.current() == ARRAY_START) {
if (arrayEndHandler != null) {
try {
if (!arrayEndHandler.onArrayEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
}
}
case COLON:
case COMMA:
case RIGHT_BRACKET:
return parseError("String_Node_Str");
default :
return parseError("String_Node_Str");
}
{
byte s=stateStack.current();
if (s == START || s == GOT_VALUE) {
stateStack.set(PARSE_COMPLETE);
}
 else if (s == MAP_NEED_VAL) {
stateStack.set(MAP_GOT_VAL);
}
 else {
stateStack.set(ARRAY_GOT_VAL);
}
}
if (stateToPush != START) {
stateStack.push(stateToPush);
}
continue around_again;
}
case MAP_START:
case MAP_NEED_KEY:
{
tok=lexer.lex(jsonText);
OnString onKey=this.onKey;
switch (tok) {
case EOF:
return true;
case ERROR:
lexicalError();
case STRING_WITH_ESCAPES:
onKey=onEscapedKey;
case STRING:
if (objectKeyHandler != null) {
try {
if (!onKey.on()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.set(MAP_SEP);
continue around_again;
case RIGHT_BRACKET:
if (stateStack.current() == MAP_START) {
if (objectEndHandler != null) {
try {
if (!objectEndHandler.onObjectEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
}
default :
return parseError("String_Node_Str");
}
}
case MAP_SEP:
{
tok=lexer.lex(jsonText);
switch (tok) {
case COLON:
stateStack.set(MAP_NEED_VAL);
continue around_again;
case EOF:
return true;
case ERROR:
lexicalError();
default :
return parseError("String_Node_Str");
}
}
case MAP_GOT_VAL:
{
tok=lexer.lex(jsonText);
switch (tok) {
case RIGHT_BRACKET:
if (objectEndHandler != null) {
try {
if (!objectEndHandler.onObjectEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
case COMMA:
stateStack.set(MAP_NEED_KEY);
continue around_again;
case EOF:
return true;
case ERROR:
lexicalError();
default :
tryRestoreErrorEffect(jsonText,startOffset);
return parseError("String_Node_Str");
}
}
case ARRAY_GOT_VAL:
{
tok=lexer.lex(jsonText);
switch (tok) {
case RIGHT_BRACE:
if (arrayEndHandler != null) {
try {
if (!arrayEndHandler.onArrayEnd()) {
stateStack.set(HANDLER_CANCEL);
return false;
}
}
 catch (Exception e) {
return handlerError(e);
}
}
stateStack.pop();
continue around_again;
case COMMA:
stateStack.set(ARRAY_NEED_VAL);
continue around_again;
case EOF:
return true;
case ERROR:
return lexicalError();
default :
return parseError("String_Node_Str");
}
}
}
}
}