Program: 12223
Project: 12223
Buggy source:
/** 
 * <p>semantic_memory.cpp:2263:smem_parse_chunk
 * @param lexer
 * @param chunks
 * @param newbies
 * @return
 * @throws IOException
 */
static boolean smem_parse_chunk(SymbolFactoryImpl symbols,Lexer lexer,Map<String,smem_chunk_value> chunks,Set<smem_chunk_lti> newbies) throws IOException {
  boolean return_val=false;
  smem_chunk_lti new_chunk=null;
  boolean good_at=false;
  ParsedLtiName chunk_name=null;
  lexer.getNextLexeme();
  if ((lexer.getCurrentLexeme().type == LexemeType.AT) || (lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER) || (lexer.getCurrentLexeme().type == LexemeType.VARIABLE)) {
    good_at=true;
    if (lexer.getCurrentLexeme().type == LexemeType.AT) {
      lexer.getNextLexeme();
      good_at=(lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER);
    }
    if (good_at) {
      chunk_name=smem_parse_lti_name(lexer.getCurrentLexeme());
      new_chunk=new smem_chunk_lti();
      new_chunk.lti_letter=chunk_name.id_letter;
      new_chunk.lti_number=chunk_name.id_number;
      new_chunk.lti_id=0;
      new_chunk.soar_id=null;
      new_chunk.slots=new HashMap<SymbolImpl,List<smem_chunk_value>>();
      lexer.getNextLexeme();
      long intermediate_counter=1;
      smem_chunk_lti intermediate_parent;
      while (lexer.getCurrentLexeme().type == LexemeType.UP_ARROW) {
        intermediate_parent=new_chunk;
        lexer.getNextLexeme();
        SymbolImpl chunk_attr=smem_parse_constant_attr(symbols,lexer.getCurrentLexeme());
        if (chunk_attr != null) {
          lexer.getNextLexeme();
          while (lexer.getCurrentLexeme().type == LexemeType.PERIOD) {
            final smem_chunk_lti temp_chunk=new smem_chunk_lti();
            temp_chunk.lti_letter=chunk_attr.asString() != null ? chunk_attr.getFirstLetter() : 'X';
            temp_chunk.lti_number=(intermediate_counter++);
            temp_chunk.lti_id=0;
            temp_chunk.slots=new HashMap<SymbolImpl,List<smem_chunk_value>>();
            temp_chunk.soar_id=null;
            final List<smem_chunk_value> s=smem_make_slot(intermediate_parent.slots,chunk_attr);
            s.add(temp_chunk);
            final String temp_key=String.format("String_Node_Str",temp_chunk.lti_letter,temp_chunk.lti_number);
            chunks.put(temp_key,temp_chunk);
            newbies.add(temp_chunk);
            intermediate_parent=temp_chunk;
            lexer.getNextLexeme();
            chunk_attr=smem_parse_constant_attr(symbols,lexer.getCurrentLexeme());
            lexer.getNextLexeme();
          }
          if (chunk_attr != null) {
            smem_chunk_value chunk_value=null;
            do {
              if ((lexer.getCurrentLexeme().type == LexemeType.SYM_CONSTANT)) {
                chunk_value=new smem_chunk_constant(symbols.createString(lexer.getCurrentLexeme().string));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.INTEGER)) {
                chunk_value=new smem_chunk_constant(symbols.createInteger(lexer.getCurrentLexeme().int_val));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.FLOAT)) {
                chunk_value=new smem_chunk_constant(symbols.createDouble(lexer.getCurrentLexeme().float_val));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.AT) || (lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER) || (lexer.getCurrentLexeme().type == LexemeType.VARIABLE)) {
                good_at=true;
                if (lexer.getCurrentLexeme().type == LexemeType.AT) {
                  lexer.getNextLexeme();
                  good_at=(lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER);
                }
                if (good_at) {
                  final ParsedLtiName temp_key2=smem_parse_lti_name(lexer.getCurrentLexeme());
                  final smem_chunk_value p=chunks.get(temp_key2.value);
                  if (p != null) {
                    chunk_value=p;
                  }
 else {
                    final smem_chunk_lti temp_chunk=new smem_chunk_lti();
                    temp_chunk.lti_letter=temp_key2.id_letter;
                    temp_chunk.lti_number=temp_key2.id_number;
                    temp_chunk.lti_id=0;
                    temp_chunk.slots=null;
                    chunk_value=temp_chunk;
                    chunks.put(temp_key2.value,chunk_value);
                    newbies.add(chunk_value.asLti());
                  }
                }
              }
              if (chunk_value != null) {
                lexer.getNextLexeme();
                final List<smem_chunk_value> s=smem_make_slot(intermediate_parent.slots,chunk_attr);
                s.add(chunk_value);
                if (lexer.getCurrentLexeme().type == LexemeType.R_PAREN) {
                  return_val=true;
                  lexer.getNextLexeme();
                  chunk_value=null;
                }
              }
            }
 while (chunk_value != null);
          }
        }
      }
    }
 else {
    }
  }
 else {
  }
  if (return_val) {
    final smem_chunk_value p=chunks.get(chunk_name.value);
    if (p == null) {
      chunks.put(chunk_name.value,new_chunk);
      newbies.add(new_chunk);
    }
 else {
      if (p.asLti().slots == null) {
        p.asLti().slots=new_chunk.slots;
        new_chunk.slots=null;
      }
 else {
        for (        Map.Entry<SymbolImpl,List<smem_chunk_value>> ss_p : new_chunk.slots.entrySet()) {
          final List<smem_chunk_value> target_slot=smem_make_slot(p.asLti().slots,ss_p.getKey());
          final List<smem_chunk_value> source_slot=ss_p.getValue();
          for (          smem_chunk_value s_p : source_slot) {
            target_slot.add(s_p);
          }
        }
        new_chunk.slots=null;
      }
      newbies.add(p.asLti());
      smem_deallocate_chunk(new_chunk);
    }
  }
 else {
    newbies.clear();
  }
  return return_val;
}

Fixed version (ground truth):
/** 
 * <p>semantic_memory.cpp:2263:smem_parse_chunk
 * @param lexer
 * @param chunks
 * @param newbies
 * @return
 * @throws IOException
 */
static boolean smem_parse_chunk(SymbolFactoryImpl symbols,Lexer lexer,Map<String,smem_chunk_value> chunks,Set<smem_chunk_lti> newbies) throws IOException {
  boolean return_val=false;
  smem_chunk_lti new_chunk=null;
  boolean good_at=false;
  ParsedLtiName chunk_name=null;
  lexer.getNextLexeme();
  if ((lexer.getCurrentLexeme().type == LexemeType.AT) || (lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER) || (lexer.getCurrentLexeme().type == LexemeType.VARIABLE)) {
    good_at=true;
    if (lexer.getCurrentLexeme().type == LexemeType.AT) {
      lexer.getNextLexeme();
      good_at=(lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER);
    }
    if (good_at) {
      chunk_name=smem_parse_lti_name(lexer.getCurrentLexeme());
      new_chunk=new smem_chunk_lti();
      new_chunk.lti_letter=chunk_name.id_letter;
      new_chunk.lti_number=chunk_name.id_number;
      new_chunk.lti_id=0;
      new_chunk.soar_id=null;
      new_chunk.slots=new HashMap<SymbolImpl,List<smem_chunk_value>>();
      lexer.getNextLexeme();
      long intermediate_counter=1;
      smem_chunk_lti intermediate_parent;
      while (lexer.getCurrentLexeme().type == LexemeType.UP_ARROW) {
        intermediate_parent=new_chunk;
        lexer.getNextLexeme();
        SymbolImpl chunk_attr=smem_parse_constant_attr(symbols,lexer.getCurrentLexeme());
        if (chunk_attr != null) {
          lexer.getNextLexeme();
          while (lexer.getCurrentLexeme().type == LexemeType.PERIOD) {
            final smem_chunk_lti temp_chunk=new smem_chunk_lti();
            temp_chunk.lti_letter=chunk_attr.asString() != null ? chunk_attr.getFirstLetter() : 'X';
            temp_chunk.lti_number=(intermediate_counter++);
            temp_chunk.lti_id=0;
            temp_chunk.slots=new HashMap<SymbolImpl,List<smem_chunk_value>>();
            temp_chunk.soar_id=null;
            final List<smem_chunk_value> s=smem_make_slot(intermediate_parent.slots,chunk_attr);
            s.add(temp_chunk);
            final String temp_key=String.format("String_Node_Str",temp_chunk.lti_letter,temp_chunk.lti_number);
            chunks.put(temp_key,temp_chunk);
            newbies.add(temp_chunk);
            intermediate_parent=temp_chunk;
            lexer.getNextLexeme();
            chunk_attr=smem_parse_constant_attr(symbols,lexer.getCurrentLexeme());
            lexer.getNextLexeme();
          }
          if (chunk_attr != null) {
            smem_chunk_value chunk_value=null;
            do {
              chunk_value=null;
              if ((lexer.getCurrentLexeme().type == LexemeType.SYM_CONSTANT)) {
                chunk_value=new smem_chunk_constant(symbols.createString(lexer.getCurrentLexeme().string));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.INTEGER)) {
                chunk_value=new smem_chunk_constant(symbols.createInteger(lexer.getCurrentLexeme().int_val));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.FLOAT)) {
                chunk_value=new smem_chunk_constant(symbols.createDouble(lexer.getCurrentLexeme().float_val));
              }
 else               if ((lexer.getCurrentLexeme().type == LexemeType.AT) || (lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER) || (lexer.getCurrentLexeme().type == LexemeType.VARIABLE)) {
                good_at=true;
                if (lexer.getCurrentLexeme().type == LexemeType.AT) {
                  lexer.getNextLexeme();
                  good_at=(lexer.getCurrentLexeme().type == LexemeType.IDENTIFIER);
                }
                if (good_at) {
                  final ParsedLtiName temp_key2=smem_parse_lti_name(lexer.getCurrentLexeme());
                  final smem_chunk_value p=chunks.get(temp_key2.value);
                  if (p != null) {
                    chunk_value=p;
                  }
 else {
                    final smem_chunk_lti temp_chunk=new smem_chunk_lti();
                    temp_chunk.lti_letter=temp_key2.id_letter;
                    temp_chunk.lti_number=temp_key2.id_number;
                    temp_chunk.lti_id=0;
                    temp_chunk.slots=null;
                    chunk_value=temp_chunk;
                    chunks.put(temp_key2.value,chunk_value);
                    newbies.add(chunk_value.asLti());
                  }
                }
              }
              if (chunk_value != null) {
                lexer.getNextLexeme();
                final List<smem_chunk_value> s=smem_make_slot(intermediate_parent.slots,chunk_attr);
                s.add(chunk_value);
                if (lexer.getCurrentLexeme().type == LexemeType.R_PAREN) {
                  return_val=true;
                  lexer.getNextLexeme();
                  chunk_value=null;
                }
              }
            }
 while (chunk_value != null);
          }
        }
      }
    }
 else {
    }
  }
 else {
  }
  if (return_val) {
    final smem_chunk_value p=chunks.get(chunk_name.value);
    if (p == null) {
      chunks.put(chunk_name.value,new_chunk);
      newbies.add(new_chunk);
    }
 else {
      if (p.asLti().slots == null) {
        p.asLti().slots=new_chunk.slots;
        new_chunk.slots=null;
      }
 else {
        for (        Map.Entry<SymbolImpl,List<smem_chunk_value>> ss_p : new_chunk.slots.entrySet()) {
          final List<smem_chunk_value> target_slot=smem_make_slot(p.asLti().slots,ss_p.getKey());
          final List<smem_chunk_value> source_slot=ss_p.getValue();
          for (          smem_chunk_value s_p : source_slot) {
            target_slot.add(s_p);
          }
        }
        new_chunk.slots=null;
      }
      newbies.add(p.asLti());
      smem_deallocate_chunk(new_chunk);
    }
  }
 else {
    newbies.clear();
  }
  return return_val;
}