Program: 64277
Project: 64277
Buggy source:
/** 
 * Sole constructor, which is private to ensure that all  IntrospectionHelpers are created via   {@link #getHelper(Class) getHelper}. Introspects the given class for bean-like methods. Each method is examined in turn, and the following rules are applied: <p> <ul> <li>If the method is <code>Task.setLocation(Location)</code>,  <code>Task.setTaskType(String)</code> or <code>TaskContainer.addTask(Task)</code>, it is ignored. These  methods are handled differently elsewhere. <li><code>void addText(String)</code> is recognised as the method for adding PCDATA to a bean. <li><code>void setFoo(Bar)</code> is recognised as a method for  setting the value of attribute <code>foo</code>, so long as  <code>Bar</code> is non-void and is not an array type. Non-String  parameter types always overload String parameter types, but that is the only guarantee made in terms of priority. <li><code>Foo createBar()</code> is recognised as a method for creating a nested element called <code>bar</code> of type  <code>Foo</code>, so long as <code>Foo</code> is not a primitive or array type. <li><code>void addConfiguredFoo(Bar)</code> is recognised as a method for storing a pre-configured element called  <code>foo</code> and of type <code>Bar</code>, so long as <code>Bar</code> is not an array, primitive or String type.  <code>Bar</code> must have an accessible constructor taking no  arguments. <li><code>void addFoo(Bar)</code> is recognised as a method for storing an element called <code>foobar</code>  and of type <code>Baz</code>, so long as <code>Baz</code> is not an array, primitive or String type.  <code>Baz</code> must have an accessible constructor taking no  arguments. </ul> Note that only one method is retained to create/set/addConfigured/add  any element or attribute.
 * @param bean The bean type to introspect. Must not be <code>null</code>.
 * @see #getHelper(Class)
 */
private IntrospectionHelper(final Class bean){
  attributeTypes=new Hashtable();
  attributeSetters=new Hashtable();
  nestedTypes=new Hashtable();
  nestedCreators=new Hashtable();
  nestedStorers=new Hashtable();
  this.bean=bean;
  Method[] methods=bean.getMethods();
  for (int i=0; i < methods.length; i++) {
    final Method m=methods[i];
    final String name=m.getName();
    Class returnType=m.getReturnType();
    Class[] args=m.getParameterTypes();
    if (org.apache.tools.ant.Task.class.isAssignableFrom(bean) && args.length == 1 && (("String_Node_Str".equals(name) && org.apache.tools.ant.Location.class.equals(args[0])) || ("String_Node_Str".equals(name) && java.lang.String.class.equals(args[0])))) {
      continue;
    }
    if (org.apache.tools.ant.TaskContainer.class.isAssignableFrom(bean) && args.length == 1 && "String_Node_Str".equals(name) && org.apache.tools.ant.Task.class.equals(args[0])) {
      continue;
    }
    if ("String_Node_Str".equals(name) && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && java.lang.String.class.equals(args[0])) {
      addText=methods[i];
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !args[0].isArray()) {
      String propName=getPropertyName(name,"String_Node_Str");
      if (attributeSetters.get(propName) != null) {
        if (java.lang.String.class.equals(args[0])) {
          continue;
        }
      }
      AttributeSetter as=createAttributeSetter(m,args[0]);
      if (as != null) {
        attributeTypes.put(propName,args[0]);
        attributeSetters.put(propName,as);
      }
    }
 else     if (name.startsWith("String_Node_Str") && !returnType.isArray() && !returnType.isPrimitive()&& args.length == 0) {
      String propName=getPropertyName(name,"String_Node_Str");
      nestedTypes.put(propName,returnType);
      nestedCreators.put(propName,new NestedCreator(){
        public Object create(        Object parent) throws InvocationTargetException, IllegalAccessException {
          return m.invoke(parent,new Object[]{});
        }
      }
);
      nestedStorers.remove(propName);
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !java.lang.String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) {
      try {
        final Constructor c=args[0].getConstructor(new Class[]{});
        String propName=getPropertyName(name,"String_Node_Str");
        nestedTypes.put(propName,args[0]);
        nestedCreators.put(propName,new NestedCreator(){
          public Object create(          Object parent) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            Object o=c.newInstance(new Object[]{});
            return o;
          }
        }
);
        nestedStorers.put(propName,new NestedStorer(){
          public void store(          Object parent,          Object child) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            m.invoke(parent,new Object[]{child});
          }
        }
);
      }
 catch (      NoSuchMethodException nse) {
      }
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !java.lang.String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) {
      try {
        final Constructor c=args[0].getConstructor(new Class[]{});
        String propName=getPropertyName(name,"String_Node_Str");
        nestedTypes.put(propName,args[0]);
        nestedCreators.put(propName,new NestedCreator(){
          public Object create(          Object parent) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            Object o=c.newInstance(new Object[]{});
            m.invoke(parent,new Object[]{o});
            return o;
          }
        }
);
        nestedStorers.remove(name);
      }
 catch (      NoSuchMethodException nse) {
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Sole constructor, which is private to ensure that all  IntrospectionHelpers are created via   {@link #getHelper(Class) getHelper}. Introspects the given class for bean-like methods. Each method is examined in turn, and the following rules are applied: <p> <ul> <li>If the method is <code>Task.setLocation(Location)</code>,  <code>Task.setTaskType(String)</code> or <code>TaskContainer.addTask(Task)</code>, it is ignored. These  methods are handled differently elsewhere. <li><code>void addText(String)</code> is recognised as the method for adding PCDATA to a bean. <li><code>void setFoo(Bar)</code> is recognised as a method for  setting the value of attribute <code>foo</code>, so long as  <code>Bar</code> is non-void and is not an array type. Non-String  parameter types always overload String parameter types, but that is the only guarantee made in terms of priority. <li><code>Foo createBar()</code> is recognised as a method for creating a nested element called <code>bar</code> of type  <code>Foo</code>, so long as <code>Foo</code> is not a primitive or array type. <li><code>void addConfiguredFoo(Bar)</code> is recognised as a method for storing a pre-configured element called  <code>foo</code> and of type <code>Bar</code>, so long as <code>Bar</code> is not an array, primitive or String type.  <code>Bar</code> must have an accessible constructor taking no  arguments. <li><code>void addFoo(Bar)</code> is recognised as a method for storing an element called <code>foobar</code>  and of type <code>Baz</code>, so long as <code>Baz</code> is not an array, primitive or String type.  <code>Baz</code> must have an accessible constructor taking no  arguments. </ul> Note that only one method is retained to create/set/addConfigured/add  any element or attribute.
 * @param bean The bean type to introspect. Must not be <code>null</code>.
 * @see #getHelper(Class)
 */
private IntrospectionHelper(final Class bean){
  attributeTypes=new Hashtable();
  attributeSetters=new Hashtable();
  nestedTypes=new Hashtable();
  nestedCreators=new Hashtable();
  nestedStorers=new Hashtable();
  this.bean=bean;
  Method[] methods=bean.getMethods();
  for (int i=0; i < methods.length; i++) {
    final Method m=methods[i];
    final String name=m.getName();
    Class returnType=m.getReturnType();
    Class[] args=m.getParameterTypes();
    if (org.apache.tools.ant.Task.class.isAssignableFrom(bean) && args.length == 1 && isHiddenSetMethod(name,args[0])) {
      continue;
    }
    if (org.apache.tools.ant.TaskContainer.class.isAssignableFrom(bean) && args.length == 1 && "String_Node_Str".equals(name) && org.apache.tools.ant.Task.class.equals(args[0])) {
      continue;
    }
    if ("String_Node_Str".equals(name) && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && java.lang.String.class.equals(args[0])) {
      addText=methods[i];
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !args[0].isArray()) {
      String propName=getPropertyName(name,"String_Node_Str");
      if (attributeSetters.get(propName) != null) {
        if (java.lang.String.class.equals(args[0])) {
          continue;
        }
      }
      AttributeSetter as=createAttributeSetter(m,args[0]);
      if (as != null) {
        attributeTypes.put(propName,args[0]);
        attributeSetters.put(propName,as);
      }
    }
 else     if (name.startsWith("String_Node_Str") && !returnType.isArray() && !returnType.isPrimitive()&& args.length == 0) {
      String propName=getPropertyName(name,"String_Node_Str");
      nestedTypes.put(propName,returnType);
      nestedCreators.put(propName,new NestedCreator(){
        public Object create(        Object parent) throws InvocationTargetException, IllegalAccessException {
          return m.invoke(parent,new Object[]{});
        }
      }
);
      nestedStorers.remove(propName);
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !java.lang.String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) {
      try {
        final Constructor c=args[0].getConstructor(new Class[]{});
        String propName=getPropertyName(name,"String_Node_Str");
        nestedTypes.put(propName,args[0]);
        nestedCreators.put(propName,new NestedCreator(){
          public Object create(          Object parent) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            Object o=c.newInstance(new Object[]{});
            return o;
          }
        }
);
        nestedStorers.put(propName,new NestedStorer(){
          public void store(          Object parent,          Object child) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            m.invoke(parent,new Object[]{child});
          }
        }
);
      }
 catch (      NoSuchMethodException nse) {
      }
    }
 else     if (name.startsWith("String_Node_Str") && java.lang.Void.TYPE.equals(returnType) && args.length == 1 && !java.lang.String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) {
      try {
        final Constructor c=args[0].getConstructor(new Class[]{});
        String propName=getPropertyName(name,"String_Node_Str");
        nestedTypes.put(propName,args[0]);
        nestedCreators.put(propName,new NestedCreator(){
          public Object create(          Object parent) throws InvocationTargetException, IllegalAccessException, InstantiationException {
            Object o=c.newInstance(new Object[]{});
            m.invoke(parent,new Object[]{o});
            return o;
          }
        }
);
        nestedStorers.remove(name);
      }
 catch (      NoSuchMethodException nse) {
      }
    }
  }
}