Program: 152676
Project: 152676
Buggy source:
public static JBossWebMetaData parse(XMLStreamReader reader,PropertyReplacer propertyReplacer) throws XMLStreamException {
  reader.require(START_DOCUMENT,null,null);
  Version version=null;
  while (reader.hasNext() && reader.next() != START_ELEMENT) {
    if (reader.getEventType() == DTD) {
      String dtdLocation=readDTDLocation(reader);
      if (dtdLocation != null) {
        version=Location.getVersion(dtdLocation);
      }
      if (version == null) {
        version=Version.JBOSS_WEB_5_0;
      }
    }
  }
  String schemaLocation=readSchemaLocation(reader);
  if (schemaLocation != null) {
    version=Location.getVersion(schemaLocation);
  }
  if (version == null) {
    version=Version.JBOSS_WEB_6_0;
  }
  JBossWebMetaData wmd=null;
switch (version) {
case JBOSS_WEB_3_0:
    wmd=new JBoss4xDTDWebMetaData();
  break;
case JBOSS_WEB_3_2:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_4_0:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_4_2:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_5_0:
wmd=new JBoss50DTDWebMetaData();
break;
case JBOSS_WEB_5_1:
wmd=new JBoss50WebMetaData();
break;
case JBOSS_WEB_6_0:
wmd=new JBoss60WebMetaData();
break;
case JBOSS_WEB_7_0:
wmd=new JBoss70WebMetaData();
break;
}
final int count=reader.getAttributeCount();
for (int i=0; i < count; i++) {
final String value=reader.getAttributeValue(i);
if (attributeHasNamespace(reader,i)) {
continue;
}
final Attribute attribute=Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case VERSION:
{
wmd.setVersion(value);
break;
}
default :
throw unexpectedAttribute(reader,i);
}
}
EnvironmentRefsGroupMetaData env=new EnvironmentRefsGroupMetaData();
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
if (EnvironmentRefsGroupMetaDataParser.parse(reader,env,propertyReplacer)) {
if (wmd.getJndiEnvironmentRefsGroup() == null) {
wmd.setJndiEnvironmentRefsGroup(env);
}
continue;
}
final Element element=Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_ROOT:
wmd.setContextRoot(getElementText(reader,propertyReplacer));
break;
case VIRTUAL_HOST:
List<String> virtualHosts=wmd.getVirtualHosts();
if (virtualHosts == null) {
virtualHosts=new ArrayList<String>();
wmd.setVirtualHosts(virtualHosts);
virtualHosts.add(getElementText(reader,propertyReplacer));
}
 else {
throw duplicateNamedElement(reader,Element.VIRTUAL_HOST.toString());
}
break;
case ANNOTATION:
JBossAnnotationsMetaData annotations=wmd.getAnnotations();
if (annotations == null) {
annotations=new JBossAnnotationsMetaData();
wmd.setAnnotations(annotations);
}
annotations.add(JBossAnnotationMetaDataParser.parse(reader,propertyReplacer));
break;
case LISTENER:
List<ContainerListenerMetaData> listeners=wmd.getContainerListeners();
if (listeners == null) {
listeners=new ArrayList<ContainerListenerMetaData>();
wmd.setContainerListeners(listeners);
}
listeners.add(ContainerListenerMetaDataParser.parse(reader,propertyReplacer));
break;
case SESSION_CONFIG:
wmd.setSessionConfig(SessionConfigMetaDataParser.parse(reader,propertyReplacer));
break;
case VALVE:
List<ValveMetaData> valves=wmd.getValves();
if (valves == null) {
valves=new ArrayList<ValveMetaData>();
wmd.setValves(valves);
}
valves.add(ValveMetaDataParser.parse(reader,propertyReplacer));
break;
case OVERLAY:
List<String> overlays=wmd.getOverlays();
if (overlays == null) {
overlays=new ArrayList<String>();
wmd.setOverlays(overlays);
}
overlays.add(getElementText(reader,propertyReplacer));
break;
case SECURITY_DOMAIN:
wmd.setSecurityDomain(getElementText(reader,propertyReplacer));
break;
case SECURITY_ROLE:
SecurityRolesMetaData securityRoles=wmd.getSecurityRoles();
if (securityRoles == null) {
securityRoles=new SecurityRolesMetaData();
wmd.setSecurityRoles(securityRoles);
}
securityRoles.add(SecurityRoleMetaDataParser.parse(reader,propertyReplacer));
break;
case JACC_STAR_ROLE_ALLOW:
wmd.setJaccAllStoreRole(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case DISABLE_CROSS_CONTEXT:
wmd.setDisableCrossContext(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case USE_JBOSS_AUTHORIZATION:
wmd.setUseJBossAuthorization(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case DISABLE_AUDIT:
wmd.setDisableAudit(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case SERVLET:
JBossServletsMetaData servlets=wmd.getServlets();
if (servlets == null) {
servlets=new JBossServletsMetaData();
wmd.setServlets(servlets);
}
servlets.add(JBossServletMetaDataParser.parse(reader,propertyReplacer));
break;
case MAX_ACTIVE_SESSIONS:
wmd.setMaxActiveSessions(Integer.valueOf(getElementText(reader,propertyReplacer)));
break;
case REPLICATION_CONFIG:
wmd.setReplicationConfig(ReplicationConfigParser.parse(reader,propertyReplacer));
break;
case PASSIVATION_CONFIG:
wmd.setPassivationConfig(PassivationConfigParser.parse(reader,propertyReplacer));
break;
case DISTINCT_NAME:
final String val=getElementText(reader,propertyReplacer);
wmd.setDistinctName(val);
break;
case SYMBOLIC_ENABLED:
wmd.setSymbolicLinking(Boolean.parseBoolean(getElementText(reader)));
break;
default :
throw unexpectedElement(reader);
}
}
return wmd;
}

Fixed version (ground truth):
public static JBossWebMetaData parse(XMLStreamReader reader,PropertyReplacer propertyReplacer) throws XMLStreamException {
  reader.require(START_DOCUMENT,null,null);
  Version version=null;
  while (reader.hasNext() && reader.next() != START_ELEMENT) {
    if (reader.getEventType() == DTD) {
      String dtdLocation=readDTDLocation(reader);
      if (dtdLocation != null) {
        version=Location.getVersion(dtdLocation);
      }
      if (version == null) {
        version=Version.JBOSS_WEB_5_0;
      }
    }
  }
  String schemaLocation=readSchemaLocation(reader);
  if (schemaLocation != null) {
    version=Location.getVersion(schemaLocation);
  }
  if (version == null) {
    version=Version.JBOSS_WEB_6_0;
  }
  JBossWebMetaData wmd=null;
switch (version) {
case JBOSS_WEB_3_0:
    wmd=new JBoss4xDTDWebMetaData();
  break;
case JBOSS_WEB_3_2:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_4_0:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_4_2:
wmd=new JBoss4xDTDWebMetaData();
break;
case JBOSS_WEB_5_0:
wmd=new JBoss50DTDWebMetaData();
break;
case JBOSS_WEB_5_1:
wmd=new JBoss50WebMetaData();
break;
case JBOSS_WEB_6_0:
wmd=new JBoss60WebMetaData();
break;
case JBOSS_WEB_7_0:
wmd=new JBoss70WebMetaData();
break;
case JBOSS_WEB_7_1:
wmd=new JBoss70WebMetaData();
break;
}
final int count=reader.getAttributeCount();
for (int i=0; i < count; i++) {
final String value=reader.getAttributeValue(i);
if (attributeHasNamespace(reader,i)) {
continue;
}
final Attribute attribute=Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case VERSION:
{
wmd.setVersion(value);
break;
}
default :
throw unexpectedAttribute(reader,i);
}
}
EnvironmentRefsGroupMetaData env=new EnvironmentRefsGroupMetaData();
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
if (EnvironmentRefsGroupMetaDataParser.parse(reader,env,propertyReplacer)) {
if (wmd.getJndiEnvironmentRefsGroup() == null) {
wmd.setJndiEnvironmentRefsGroup(env);
}
continue;
}
final Element element=Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_ROOT:
wmd.setContextRoot(getElementText(reader,propertyReplacer));
break;
case VIRTUAL_HOST:
List<String> virtualHosts=wmd.getVirtualHosts();
if (virtualHosts == null) {
virtualHosts=new ArrayList<String>();
wmd.setVirtualHosts(virtualHosts);
virtualHosts.add(getElementText(reader,propertyReplacer));
}
 else {
throw duplicateNamedElement(reader,Element.VIRTUAL_HOST.toString());
}
break;
case ANNOTATION:
JBossAnnotationsMetaData annotations=wmd.getAnnotations();
if (annotations == null) {
annotations=new JBossAnnotationsMetaData();
wmd.setAnnotations(annotations);
}
annotations.add(JBossAnnotationMetaDataParser.parse(reader,propertyReplacer));
break;
case LISTENER:
List<ContainerListenerMetaData> listeners=wmd.getContainerListeners();
if (listeners == null) {
listeners=new ArrayList<ContainerListenerMetaData>();
wmd.setContainerListeners(listeners);
}
listeners.add(ContainerListenerMetaDataParser.parse(reader,propertyReplacer));
break;
case SESSION_CONFIG:
wmd.setSessionConfig(SessionConfigMetaDataParser.parse(reader,propertyReplacer));
break;
case VALVE:
List<ValveMetaData> valves=wmd.getValves();
if (valves == null) {
valves=new ArrayList<ValveMetaData>();
wmd.setValves(valves);
}
valves.add(ValveMetaDataParser.parse(reader,propertyReplacer));
break;
case OVERLAY:
List<String> overlays=wmd.getOverlays();
if (overlays == null) {
overlays=new ArrayList<String>();
wmd.setOverlays(overlays);
}
overlays.add(getElementText(reader,propertyReplacer));
break;
case SECURITY_DOMAIN:
wmd.setSecurityDomain(getElementText(reader,propertyReplacer));
break;
case SECURITY_ROLE:
SecurityRolesMetaData securityRoles=wmd.getSecurityRoles();
if (securityRoles == null) {
securityRoles=new SecurityRolesMetaData();
wmd.setSecurityRoles(securityRoles);
}
securityRoles.add(SecurityRoleMetaDataParser.parse(reader,propertyReplacer));
break;
case JACC_STAR_ROLE_ALLOW:
wmd.setJaccAllStoreRole(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case DISABLE_CROSS_CONTEXT:
wmd.setDisableCrossContext(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case USE_JBOSS_AUTHORIZATION:
wmd.setUseJBossAuthorization(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case DISABLE_AUDIT:
wmd.setDisableAudit(Boolean.valueOf(getElementText(reader,propertyReplacer)));
break;
case SERVLET:
JBossServletsMetaData servlets=wmd.getServlets();
if (servlets == null) {
servlets=new JBossServletsMetaData();
wmd.setServlets(servlets);
}
servlets.add(JBossServletMetaDataParser.parse(reader,propertyReplacer));
break;
case MAX_ACTIVE_SESSIONS:
wmd.setMaxActiveSessions(Integer.valueOf(getElementText(reader,propertyReplacer)));
break;
case REPLICATION_CONFIG:
wmd.setReplicationConfig(ReplicationConfigParser.parse(reader,propertyReplacer));
break;
case PASSIVATION_CONFIG:
wmd.setPassivationConfig(PassivationConfigParser.parse(reader,propertyReplacer));
break;
case DISTINCT_NAME:
final String val=getElementText(reader,propertyReplacer);
wmd.setDistinctName(val);
break;
case SYMBOLIC_ENABLED:
wmd.setSymbolicLinkingEnabled(Boolean.parseBoolean(getElementText(reader,propertyReplacer)));
break;
default :
throw unexpectedElement(reader);
}
}
return wmd;
}