Program: 25052
Project: 25052
Buggy source:
@Test public void testUDFManagement(){
  ADQLParser parser=new ADQLParser(new DBChecker(tables,new ArrayList<FunctionDef>(0)));
  try {
    assertNotNull(parser.parseQuery("String_Node_Str"));
  }
 catch (  ParseException e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  FunctionDef[] udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR)),new FunctionDef("String_Node_Str",new DBType(DBDatatype.INTEGER))};
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    assertNotNull(parser.parseQuery("String_Node_Str"));
    assertNotNull(parser.parseQuery("String_Node_Str"));
  }
 catch (  ParseException e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR),new FunctionParam[]{new FunctionParam("String_Node_Str",new DBType(DBDatatype.VARCHAR))})};
  udfs[0].setUDFClass(UDFToto.class);
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    ADQLQuery query=parser.parseQuery("String_Node_Str");
    assertNotNull(query);
    Iterator<ADQLObject> it=query.search(new SimpleSearchHandler(){
      @Override protected boolean match(      ADQLObject obj){
        return (obj instanceof UserDefinedFunction) && ((UserDefinedFunction)obj).getName().equals("String_Node_Str");
      }
    }
);
    assertTrue(it.hasNext());
    assertEquals(UDFToto.class.getName(),it.next().getClass().getName());
    assertFalse(it.hasNext());
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  Exception e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR),new FunctionParam[]{new FunctionParam("String_Node_Str",new DBType(DBDatatype.VARCHAR))})};
  udfs[0].setUDFClass(WrongUDFToto.class);
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  Exception e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
}

Fixed version (ground truth):
@Test public void testUDFManagement(){
  ADQLParser parser=new ADQLParser(new DBChecker(tables,new ArrayList<FunctionDef>(0)));
  try {
    assertNotNull(parser.parseQuery("String_Node_Str"));
  }
 catch (  ParseException e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  FunctionDef[] udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR)),new FunctionDef("String_Node_Str",new DBType(DBDatatype.INTEGER))};
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    assertNotNull(parser.parseQuery("String_Node_Str"));
    assertNotNull(parser.parseQuery("String_Node_Str"));
  }
 catch (  ParseException e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ParseException e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(2,ex.getNbErrors());
    Iterator<ParseException> errors=ex.getErrors();
    assertEquals("String_Node_Str",errors.next().getMessage());
    assertEquals("String_Node_Str",errors.next().getMessage());
  }
  udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR),new FunctionParam[]{new FunctionParam("String_Node_Str",new DBType(DBDatatype.VARCHAR))})};
  udfs[0].setUDFClass(UDFToto.class);
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    ADQLQuery query=parser.parseQuery("String_Node_Str");
    assertNotNull(query);
    Iterator<ADQLObject> it=query.search(new SimpleSearchHandler(){
      @Override protected boolean match(      ADQLObject obj){
        return (obj instanceof UserDefinedFunction) && ((UserDefinedFunction)obj).getName().equals("String_Node_Str");
      }
    }
);
    assertTrue(it.hasNext());
    assertEquals(UDFToto.class.getName(),it.next().getClass().getName());
    assertFalse(it.hasNext());
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail("String_Node_Str");
  }
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  Exception e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
  udfs=new FunctionDef[]{new FunctionDef("String_Node_Str",new DBType(DBDatatype.VARCHAR),new FunctionParam[]{new FunctionParam("String_Node_Str",new DBType(DBDatatype.VARCHAR))})};
  udfs[0].setUDFClass(WrongUDFToto.class);
  parser=new ADQLParser(new DBChecker(tables,Arrays.asList(udfs)));
  try {
    parser.parseQuery("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  Exception e) {
    assertTrue(e instanceof UnresolvedIdentifiersException);
    UnresolvedIdentifiersException ex=(UnresolvedIdentifiersException)e;
    assertEquals(1,ex.getNbErrors());
    assertEquals("String_Node_Str",ex.getErrors().next().getMessage());
  }
}