nus-yam/ex-repair huggingface dataset:
Program: 64606
Project: 64606
Buggy source:
/** 
 * Add any data required prior to marshalling an entity to XML or JSON In general, this will only affect fields that have been weaved into the object
 * @param entity
 */
protected void preMarshallIndividualEntity(Object entity){
  if (entity instanceof PersistenceWeavedRest) {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(entity.getClass());
    if (descriptor != null) {
      ((PersistenceWeavedRest)entity)._persistence_setRelationships(new ArrayList<RelationshipInfo>());
      for (      DatabaseMapping mapping : descriptor.getMappings()) {
        if (mapping.isForeignReferenceMapping()) {
          ForeignReferenceMapping frMapping=(ForeignReferenceMapping)mapping;
          RelationshipInfo info=new RelationshipInfo();
          info.setAttributeName(frMapping.getAttributeName());
          info.setOwningEntity(entity);
          info.setOwningEntityAlias(descriptor.getAlias());
          info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity,getJpaSession()));
          ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Add any data required prior to marshalling an entity to XML or JSON In general, this will only affect fields that have been weaved into the object
 * @param entity
 */
protected void preMarshallIndividualEntity(Object entity){
  if (entity instanceof PersistenceWeavedRest) {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(entity.getClass());
    if (descriptor != null) {
      ((PersistenceWeavedRest)entity)._persistence_setRelationships(new ArrayList<RelationshipInfo>());
      for (      DatabaseMapping mapping : descriptor.getMappings()) {
        if (mapping.isForeignReferenceMapping()) {
          ForeignReferenceMapping frMapping=(ForeignReferenceMapping)mapping;
          RelationshipInfo info=new RelationshipInfo();
          info.setAttributeName(frMapping.getAttributeName());
          info.setOwningEntity(entity);
          info.setOwningEntityAlias(descriptor.getAlias());
          info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity,(AbstractSession)getJpaSession()));
          ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
        }
      }
    }
  }
}
Program: 64607
Project: 64607
Buggy source:
@SuppressWarnings("String_Node_Str") public Response callSessionBean(HttpHeaders hh,UriInfo ui,URI baseURI,InputStream is) throws JAXBException, ClassNotFoundException, NamingException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
  SessionBeanCall call=null;
  call=unmarshallSessionBeanCall(is);
  String jndiName=call.getJndiName();
  javax.naming.Context ctx=new InitialContext();
  Object ans=ctx.lookup(jndiName);
  if (ans == null) {
    JPARSLogger.fine("String_Node_Str",new Object[]{jndiName});
    return Response.status(Status.NOT_FOUND).build();
  }
  PersistenceContext context=null;
  if (call.getContext() != null) {
    context=getPersistenceFactory().get(call.getContext(),baseURI,null);
    if (context == null) {
      JPARSLogger.fine("String_Node_Str",new Object[]{call.getContext()});
      return Response.status(Status.NOT_FOUND).build();
    }
  }
  Class[] parameters=new Class[call.getParameters().size()];
  Object[] args=new Object[call.getParameters().size()];
  int i=0;
  for (  Parameter param : call.getParameters()) {
    Class parameterClass=null;
    Object parameterValue=null;
    if (context != null) {
      parameterClass=context.getClass(param.getTypeName());
    }
    if (parameterClass != null) {
      parameterValue=context.unmarshalEntity(param.getTypeName(),hh.getMediaType(),is);
    }
 else {
      parameterClass=Thread.currentThread().getContextClassLoader().loadClass(param.getTypeName());
      parameterValue=ConversionManager.getDefaultManager().convertObject(param.getValue(),parameterClass);
    }
    parameters[i]=parameterClass;
    args[i]=parameterValue;
    i++;
  }
  Method method=ans.getClass().getMethod(call.getMethodName(),parameters);
  Object returnValue=method.invoke(ans,args);
  return Response.ok(new StreamingOutputMarshaller(null,returnValue,hh.getAcceptableMediaTypes())).build();
}

Fixed version (ground truth):
@POST @Produces(MediaType.WILDCARD) public Response callSessionBean(@Context HttpHeaders hh,@Context UriInfo ui,InputStream is) throws JAXBException, ClassNotFoundException, NamingException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
  return callSessionBeanInternal(hh,ui,is);
}
Program: 64609
Project: 64609
Buggy source:
public DynamicXMLMetadataSource(Server session,String packageName){
  ObjectFactory objectFactory=new ObjectFactory();
  xmlBindings=new XmlBindings();
  xmlBindings.setPackageName(packageName);
  JavaTypes javaTypes=new JavaTypes();
  xmlBindings.setJavaTypes(javaTypes);
  XmlSchema xmlSchema=new XmlSchema();
  XmlNs atomNs=new XmlNs();
  atomNs.setPrefix(LINK_PREFIX);
  atomNs.setNamespaceUri(LINK_NAMESPACE_URI);
  xmlSchema.getXmlNs().add(atomNs);
  xmlBindings.setXmlSchema(xmlSchema);
  for (  ClassDescriptor ormDescriptor : session.getProject().getOrderedDescriptors()) {
    String descriptorPackageName="String_Node_Str";
    if (ormDescriptor.getJavaClassName().lastIndexOf('.') > 0) {
      descriptorPackageName=ormDescriptor.getJavaClassName().substring(0,ormDescriptor.getJavaClassName().lastIndexOf('.'));
    }
    if (descriptorPackageName.equals(packageName)) {
      javaTypes.getJavaType().add(createJAXBType(ormDescriptor,objectFactory));
    }
  }
}

Fixed version (ground truth):
public DynamicXMLMetadataSource(DatabaseSession session,String packageName){
  ObjectFactory objectFactory=new ObjectFactory();
  xmlBindings=new XmlBindings();
  xmlBindings.setPackageName(packageName);
  JavaTypes javaTypes=new JavaTypes();
  xmlBindings.setJavaTypes(javaTypes);
  XmlSchema xmlSchema=new XmlSchema();
  XmlNs atomNs=new XmlNs();
  atomNs.setPrefix(LINK_PREFIX);
  atomNs.setNamespaceUri(LINK_NAMESPACE_URI);
  xmlSchema.getXmlNs().add(atomNs);
  xmlBindings.setXmlSchema(xmlSchema);
  for (  ClassDescriptor ormDescriptor : session.getProject().getOrderedDescriptors()) {
    String descriptorPackageName="String_Node_Str";
    if (ormDescriptor.getJavaClassName().lastIndexOf('.') > 0) {
      descriptorPackageName=ormDescriptor.getJavaClassName().substring(0,ormDescriptor.getJavaClassName().lastIndexOf('.'));
    }
    if (descriptorPackageName.equals(packageName)) {
      javaTypes.getJavaType().add(createJAXBType(ormDescriptor,objectFactory));
    }
  }
}
Program: 64613
Project: 64613
Buggy source:
@Override public Object unmarshal(String v) throws Exception {
  if (v.equals("String_Node_Str")) {
    return null;
  }
  String fixedString=v.replace("String_Node_Str","String_Node_Str");
  int lastSlash=fixedString.lastIndexOf('/');
  String entityType=fixedString.substring((baseURI + context.getName() + "String_Node_Str").length(),lastSlash);
  String entityId=fixedString.substring(lastSlash + 1);
  ClassDescriptor descriptor=context.getDescriptor(entityType);
  Object id=IdHelper.buildId(context,descriptor.getAlias(),entityId,null);
  return constructObjectForId(entityType,id);
}

Fixed version (ground truth):
@Override public Object unmarshal(String v) throws Exception {
  if (v.equals("String_Node_Str")) {
    return null;
  }
  String fixedString=v.replace("String_Node_Str","String_Node_Str");
  int lastSlash=fixedString.lastIndexOf('/');
  String entityType=fixedString.substring((baseURI + context.getName() + "String_Node_Str").length(),lastSlash);
  String entityId=fixedString.substring(lastSlash + 1);
  ClassDescriptor descriptor=context.getDescriptor(entityType);
  Object id=IdHelper.buildId(context,descriptor.getAlias(),entityId);
  return constructObjectForId(entityType,id);
}
Program: 64615
Project: 64615
Buggy source:
@Test public void verifyJPAConfig(){
  Assert.assertNotNull(context);
  EntityManagerFactory emf=context.getEmf();
  Assert.assertNotNull(emf);
  Server session=JpaHelper.getServerSession(emf);
  Assert.assertEquals(3,session.getDescriptors().size());
}

Fixed version (ground truth):
@Test public void verifyJPAConfig(){
  Assert.assertNotNull(context);
  EntityManagerFactory emf=context.getEmf();
  Assert.assertNotNull(emf);
  DatabaseSession session=JpaHelper.getServerSession(emf);
  Assert.assertEquals(3,session.getDescriptors().size());
}
Program: 64619
Project: 64619
Buggy source:
/** 
 * Return the JDBC type name for a given JDBC type code.
 */
public static String getJDBCTypeNameFromType(int jdbcType){
  String typeName=OTHER_STR;
switch (jdbcType) {
case Types.NUMERIC:
    typeName=NUMERIC_STR;
  break;
case Types.VARCHAR:
typeName=VARCHAR_STR;
break;
case Types.NVARCHAR:
typeName=NVARCHAR_STR;
break;
case Types.DECIMAL:
typeName=DECIMAL_STR;
break;
case Types.CHAR:
typeName=CHAR_STR;
break;
case Types.NCHAR:
typeName=NCHAR_STR;
break;
case Types.FLOAT:
typeName=FLOAT_STR;
break;
case Types.REAL:
typeName=REAL_STR;
break;
case Types.DOUBLE:
typeName=DOUBLE_STR;
break;
case Types.BINARY:
typeName=BINARY_STR;
break;
case Types.BLOB:
typeName=BLOB_STR;
break;
case Types.CLOB:
typeName=CLOB_STR;
break;
case Types.NCLOB:
typeName=NCLOB_STR;
break;
case Types.VARBINARY:
typeName=VARBINARY_STR;
break;
case Types.LONGVARBINARY:
typeName=LONGVARBINARY_STR;
break;
case Types.DATE:
typeName=DATE_STR;
break;
case Types.TIME:
typeName=TIME_STR;
break;
case Types.TIMESTAMP:
typeName=TIMESTAMP_STR;
break;
case Types.BIGINT:
typeName=BIGINT_STR;
break;
case Types.ARRAY:
typeName=ARRAY_STR;
break;
case Types.STRUCT:
typeName=STRUCT_STR;
break;
}
return typeName;
}

Fixed version (ground truth):
/** 
 * Return the JDBC type name for a given JDBC type code.
 */
public static String getJDBCTypeNameFromType(int jdbcType){
  String typeName=OTHER_STR;
switch (jdbcType) {
case Types.NUMERIC:
    typeName=NUMERIC_STR;
  break;
case Types.VARCHAR:
typeName=VARCHAR_STR;
break;
case Types.NVARCHAR:
typeName=NVARCHAR_STR;
break;
case Types.DECIMAL:
typeName=DECIMAL_STR;
break;
case Types.CHAR:
typeName=CHAR_STR;
break;
case Types.NCHAR:
typeName=NCHAR_STR;
break;
case Types.FLOAT:
typeName=FLOAT_STR;
break;
case Types.REAL:
typeName=REAL_STR;
break;
case Types.DOUBLE:
typeName=DOUBLE_STR;
break;
case Types.BINARY:
typeName=BINARY_STR;
break;
case Types.BLOB:
typeName=BLOB_STR;
break;
case Types.CLOB:
typeName=CLOB_STR;
break;
case Types.NCLOB:
typeName=NCLOB_STR;
break;
case Types.VARBINARY:
typeName=VARBINARY_STR;
break;
case Types.LONGVARBINARY:
typeName=LONGVARBINARY_STR;
break;
case Types.DATE:
typeName=DATE_STR;
break;
case Types.TIME:
typeName=TIME_STR;
break;
case Types.TIMESTAMP:
typeName=TIMESTAMP_STR;
break;
case Types.BIGINT:
typeName=BIGINT_STR;
break;
case Types.ARRAY:
typeName=ARRAY_STR;
break;
case Types.STRUCT:
typeName=STRUCT_STR;
break;
case Types.ROWID:
typeName=ROWID_STR;
break;
}
return typeName;
}
Program: 64620
Project: 64620
Buggy source:
/** 
 * Return the XML type (as a QName) associated with the given JDBC type.
 */
public static QName getXMLTypeFromJDBCType(int jdbcType){
switch (jdbcType) {
case CHAR:
case NCHAR:
case LONGVARCHAR:
case VARCHAR:
case NVARCHAR:
case CLOB:
case NCLOB:
    return STRING_QNAME;
case BIGINT:
  return INTEGER_QNAME;
case INTEGER:
case SMALLINT:
case TINYINT:
return INT_QNAME;
case NUMERIC:
case DECIMAL:
return DECIMAL_QNAME;
case DOUBLE:
case FLOAT:
case REAL:
return DOUBLE_QNAME;
case DATE:
return DATE_QNAME;
case TIME:
return TIME_QNAME;
case TIMESTAMP:
return DATE_TIME_QNAME;
default :
return BASE_64_BINARY_QNAME;
}
}

Fixed version (ground truth):
/** 
 * Return the XML type (as a QName) associated with the given JDBC type.
 */
public static QName getXMLTypeFromJDBCType(int jdbcType){
switch (jdbcType) {
case CHAR:
case NCHAR:
case LONGVARCHAR:
case VARCHAR:
case NVARCHAR:
case CLOB:
case NCLOB:
case ROWID:
    return STRING_QNAME;
case BIGINT:
  return INTEGER_QNAME;
case INTEGER:
case SMALLINT:
case TINYINT:
return INT_QNAME;
case NUMERIC:
case DECIMAL:
return DECIMAL_QNAME;
case DOUBLE:
case FLOAT:
case REAL:
return DOUBLE_QNAME;
case DATE:
return DATE_QNAME;
case TIME:
return TIME_QNAME;
case TIMESTAMP:
return DATE_TIME_QNAME;
default :
return BASE_64_BINARY_QNAME;
}
}
Program: 64623
Project: 64623
Buggy source:
public void testSetCollectionItemByXPath(){
  Customer customer=new Customer();
  PhoneNumber pn1=new PhoneNumber();
  customer.getPhoneNumbers().add(pn1);
  PhoneNumber pn2=new PhoneNumber();
  customer.getPhoneNumbers().add(pn2);
  PhoneNumber newPN2=new PhoneNumber();
  xmlContext.setValueByXPath(customer,"String_Node_Str",namespaceResolver,newPN2);
  assertSame(pn1,customer.getPhoneNumbers().get(0));
  assertSame(newPN2,customer.getPhoneNumbers().get(1));
  assertSame(pn2,customer.getPhoneNumbers().get(2));
}

Fixed version (ground truth):
public void testSetCollectionItemByXPath(){
  Customer customer=new Customer();
  PhoneNumber pn1=new PhoneNumber();
  customer.getPhoneNumbers().add(pn1);
  PhoneNumber pn2=new PhoneNumber();
  customer.getPhoneNumbers().add(pn2);
  PhoneNumber newPN2=new PhoneNumber();
  xmlContext.setValueByXPath(customer,"String_Node_Str",namespaceResolver,newPN2);
  assertSame(pn1,customer.getPhoneNumbers().get(0));
  assertSame(newPN2,customer.getPhoneNumbers().get(1));
}
Program: 64624
Project: 64624
Buggy source:
public void testSetCollectionItemByXPath(){
  Customer customer=new Customer();
  PhoneNumber pn1=new PhoneNumber();
  customer.getPhoneNumbers().add(pn1);
  PhoneNumber pn2=new PhoneNumber();
  customer.getPhoneNumbers().add(pn2);
  PhoneNumber newPN2=new PhoneNumber();
  xmlContext.setValueByXPath(customer,"String_Node_Str",null,newPN2);
  assertSame(pn1,customer.getPhoneNumbers().get(0));
  assertSame(newPN2,customer.getPhoneNumbers().get(1));
  assertSame(pn2,customer.getPhoneNumbers().get(2));
}

Fixed version (ground truth):
public void testSetCollectionItemByXPath(){
  Customer customer=new Customer();
  PhoneNumber pn1=new PhoneNumber();
  customer.getPhoneNumbers().add(pn1);
  PhoneNumber pn2=new PhoneNumber();
  customer.getPhoneNumbers().add(pn2);
  PhoneNumber newPN2=new PhoneNumber();
  xmlContext.setValueByXPath(customer,"String_Node_Str",null,newPN2);
  assertSame(pn1,customer.getPhoneNumbers().get(0));
  assertSame(newPN2,customer.getPhoneNumbers().get(1));
}
Program: 64625
Project: 64625
Buggy source:
/** 
 * INTERNAL: Helper to build a HashMap to help in the construction of a CompositeData
 * @param String mappedClassName: fullyQualified class name of the class
 * @return HashMap
 */
private HashMap buildLowlevelDetailsFor(String mappedClassName){
  Class mappedClass=(Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(mappedClassName,ClassConstants.CLASS);
  IdentityMap identityMap=getSession().getIdentityMapAccessorInstance().getIdentityMap(mappedClass);
  ClassDescriptor descriptor=getSession().getProject().getDescriptor(mappedClass);
  String cacheType=getCacheTypeFor(identityMap.getClass());
  String configuredSize="String_Node_Str" + identityMap.getMaxSize();
  String currentSize="String_Node_Str";
  currentSize="String_Node_Str" + identityMap.getSize(mappedClass,true);
  String parentClassName="String_Node_Str";
  boolean isChildDescriptor=descriptor.isChildDescriptor();
  HashMap details=new HashMap();
  details.put("String_Node_Str",mappedClassName);
  details.put("String_Node_Str",(isChildDescriptor ? "String_Node_Str" : cacheType));
  details.put("String_Node_Str",(isChildDescriptor ? "String_Node_Str" : configuredSize));
  details.put("String_Node_Str",currentSize);
  if (descriptor.hasInheritance()) {
    if (descriptor.getInheritancePolicy().getParentDescriptor() != null) {
      parentClassName=descriptor.getInheritancePolicy().getParentClassName();
    }
  }
  details.put("String_Node_Str",parentClassName);
  return details;
}

Fixed version (ground truth):
/** 
 * INTERNAL: Helper to build a HashMap to help in the construction of a CompositeData
 * @param String mappedClassName: fullyQualified class name of the class
 * @return HashMap
 */
private HashMap buildLowlevelDetailsFor(String mappedClassName){
  Class mappedClass=(Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(mappedClassName,ClassConstants.CLASS);
  ClassDescriptor descriptor=getSession().getProject().getDescriptor(mappedClass);
  String cacheType="String_Node_Str";
  String configuredSize="String_Node_Str";
  String currentSize="String_Node_Str";
  String parentClassName="String_Node_Str";
  if (!descriptor.isAggregateDescriptor()) {
    IdentityMap identityMap=getSession().getIdentityMapAccessorInstance().getIdentityMap(descriptor);
    cacheType=getCacheTypeFor(identityMap.getClass());
    configuredSize=String.valueOf(identityMap.getMaxSize());
    currentSize=String.valueOf(identityMap.getSize(mappedClass,true));
  }
  if (descriptor.hasInheritance()) {
    if (descriptor.getInheritancePolicy().getParentDescriptor() != null) {
      parentClassName=descriptor.getInheritancePolicy().getParentClassName();
    }
  }
  boolean isChildDescriptor=descriptor.isChildDescriptor();
  HashMap details=new HashMap(5);
  details.put("String_Node_Str",mappedClassName);
  details.put("String_Node_Str",(isChildDescriptor ? "String_Node_Str" : cacheType));
  details.put("String_Node_Str",(isChildDescriptor ? "String_Node_Str" : configuredSize));
  details.put("String_Node_Str",currentSize);
  details.put("String_Node_Str",parentClassName);
  return details;
}
Program: 64626
Project: 64626
Buggy source:
/** 
 * INTERNAL: Convert the TabularData to a two-dimensional array
 * @param tdata the TabularData to be converted
 * @param names the order of the columns
 * @return a two-dimensional array
 * @throws Exception
 */
private Object[][] tabularDataTo2DArray(TabularData tdata,String[] names) throws Exception {
  if (tdata == null) {
    return null;
  }
  Object[] rows=tdata.values().toArray();
  Object[][] data=new Object[rows.length][];
  for (int i=0; i < rows.length; i++) {
    data[i]=((CompositeData)rows[i]).getAll(names);
  }
  return data;
}

Fixed version (ground truth):
/** 
 * INTERNAL: Convert the TabularData to a two-dimensional array
 * @param tdata the TabularData to be converted
 * @param names the order of the columns
 * @return a two-dimensional array
 * @throws Exception
 */
private Object[][] tabularDataTo2DArray(TabularData tdata,String[] names) throws Exception {
  if (tdata == null) {
    return null;
  }
  Object[] rows=tdata.values().toArray();
  Object[][] data=new Object[rows.length][];
  for (int i=0; i < rows.length; i++) {
    CompositeData cdata=((CompositeData)rows[i]);
    Object[] returnRow=new Object[names.length];
    for (int j=0; j < names.length; j++) {
      String name=names[j];
      Object value=cdata.get(name);
      returnRow[j]=name + "String_Node_Str" + String.valueOf(value);
    }
    data[i]=returnRow;
  }
  return data;
}
Program: 64627
Project: 64627
Buggy source:
/** 
 * Returns true if the SELECT clause consists of a single expression returning the base identification variable of the query and if the base variable is defined as a range variable w/o FETCH JOINs.
 */
private boolean isReadAllQuery(ParseTreeContext context){
  if (!isSingleSelectExpression()) {
    return false;
  }
  Node node=getFirstSelectExpressionNode();
  if (!node.isVariableNode()) {
    return false;
  }
  String variable=((VariableNode)node).getCanonicalVariableName();
  String baseVariable=getParseTree().getFromNode().getFirstVariable();
  if (!context.isRangeVariable(baseVariable)) {
    return false;
  }
  return baseVariable.equals(variable);
}

Fixed version (ground truth):
/** 
 * Returns true if the SELECT clause consists of a single expression returning the base identification variable of the query and if the base variable is defined as a range variable w/o FETCH JOINs.
 */
private boolean isReadAllQuery(ParseTreeContext context){
  if (!isSingleSelectExpression()) {
    return false;
  }
  Node node=getFirstSelectExpressionNode();
  if (!node.isVariableNode()) {
    return false;
  }
  String variable=((VariableNode)node).getCanonicalVariableName();
  String baseVariable=getParseTree().getFromNode().getFirstVariable();
  if (!context.isRangeVariable(baseVariable)) {
    return false;
  }
  if (getParseTree().hasGroupBy() || getParseTree().hasHaving()) {
    return false;
  }
  return baseVariable.equals(variable);
}
Program: 64629
Project: 64629
Buggy source:
private void processReferencePropertyTypes(Property property,TypeInfo info,JavaClass theClass){
  for (  org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
    JavaClass type=property.getType();
    String typeName=type.getQualifiedName();
    if (isCollectionType(property)) {
      if (type.hasActualTypeArguments()) {
        type=property.getGenericType();
        typeName=type.getQualifiedName();
      }
    }
    if (JAVAX_XML_BIND_JAXBELEMENT.equals(typeName) && type.getActualTypeArguments().size() > 0) {
      JavaClass theType=(JavaClass)type.getActualTypeArguments().iterator().next();
      TypeInfo refTypeInfo=typeInfo.get(theType.getQualifiedName());
      if (refTypeInfo == null && shouldGenerateTypeInfo(theType)) {
        JavaClass[] jClassArray=new JavaClass[]{theType};
        buildNewTypeInfo(jClassArray);
      }
    }
    if (!(nextRef.getType().equals("String_Node_Str") || nextRef.getType().equals("String_Node_Str"))) {
      typeName=nextRef.getType();
      type=helper.getJavaClass(typeName);
    }
    TypeInfo refTypeInfo=typeInfo.get(type.getQualifiedName());
    if (refTypeInfo == null && shouldGenerateTypeInfo(type)) {
      JavaClass[] jClassArray=new JavaClass[]{type};
      buildNewTypeInfo(jClassArray);
    }
  }
}

Fixed version (ground truth):
private void processReferencePropertyTypes(Property property,TypeInfo info,JavaClass theClass){
  for (  org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
    JavaClass type=property.getType();
    String typeName=type.getQualifiedName();
    if (isCollectionType(property)) {
      if (type.hasActualTypeArguments()) {
        type=property.getGenericType();
        typeName=type.getQualifiedName();
      }
    }
    if (JAVAX_XML_BIND_JAXBELEMENT.equals(typeName)) {
      Collection args=type.getActualTypeArguments();
      if (args.size() > 0) {
        JavaClass theType=(JavaClass)args.iterator().next();
        TypeInfo refTypeInfo=typeInfo.get(theType.getQualifiedName());
        if (refTypeInfo == null && shouldGenerateTypeInfo(theType)) {
          JavaClass[] jClassArray=new JavaClass[]{theType};
          buildNewTypeInfo(jClassArray);
        }
      }
    }
    if (!(nextRef.getType().equals("String_Node_Str") || nextRef.getType().equals("String_Node_Str"))) {
      typeName=nextRef.getType();
      type=helper.getJavaClass(typeName);
    }
    TypeInfo refTypeInfo=typeInfo.get(type.getQualifiedName());
    if (refTypeInfo == null && shouldGenerateTypeInfo(type)) {
      JavaClass[] jClassArray=new JavaClass[]{type};
      buildNewTypeInfo(jClassArray);
    }
  }
}
Program: 64635
Project: 64635
Buggy source:
public void setType(JavaClass cls){
  if (cls == null) {
    return;
  }
  if (type != null && type == cls) {
    return;
  }
  String clsName=cls.getRawName();
  if (isCollectionType(cls)) {
    if (cls.hasActualTypeArguments()) {
      ArrayList typeArgs=(ArrayList)cls.getActualTypeArguments();
      if (typeArgs.size() > 0) {
        genericType=(JavaClass)typeArgs.get(0);
      }
 else {
        genericType=helper.getJavaClass(Object.class);
      }
    }
 else {
      genericType=helper.getJavaClass(Object.class);
    }
    type=cls;
  }
 else   if (cls.isArray() && !clsName.equals("String_Node_Str")) {
    type=cls;
    genericType=cls.getComponentType();
  }
 else {
    type=cls;
    genericType=null;
  }
  boolean isNewTypeMap=helper.getJavaClass(java.util.Map.class).isAssignableFrom(type);
  setIsMap(isNewTypeMap);
  if (isMap()) {
    Object[] types=type.getActualTypeArguments().toArray();
    if (types.length >= 2) {
      keyType=(JavaClass)types[0];
      valueType=(JavaClass)types[1];
    }
 else {
      keyType=helper.getJavaClass(Object.class);
      valueType=helper.getJavaClass(Object.class);
    }
  }
}

Fixed version (ground truth):
public void setType(JavaClass cls){
  if (cls == null) {
    return;
  }
  if (type != null && type == cls) {
    return;
  }
  String clsName=cls.getRawName();
  if (isCollectionType(cls)) {
    Collection typeArgs=cls.getActualTypeArguments();
    if (typeArgs.size() > 0) {
      genericType=(JavaClass)typeArgs.iterator().next();
    }
 else {
      genericType=helper.getJavaClass(Object.class);
    }
    type=cls;
  }
 else   if (cls.isArray() && !clsName.equals("String_Node_Str")) {
    type=cls;
    genericType=cls.getComponentType();
  }
 else {
    type=cls;
    genericType=null;
  }
  boolean isNewTypeMap=helper.getJavaClass(java.util.Map.class).isAssignableFrom(type);
  setIsMap(isNewTypeMap);
  if (isMap()) {
    Object[] types=type.getActualTypeArguments().toArray();
    if (types.length >= 2) {
      keyType=(JavaClass)types[0];
      valueType=(JavaClass)types[1];
    }
 else {
      keyType=helper.getJavaClass(Object.class);
      valueType=helper.getJavaClass(Object.class);
    }
  }
}
Program: 64636
Project: 64636
Buggy source:
/** 
 * Return a given method's generic return type as a JavaClass.
 * @param meth
 * @return
 */
public JavaClass getGenericReturnType(JavaMethod meth){
  JavaClass result=meth.getReturnType();
  JavaClass jClass=null;
  if (result == null) {
    return null;
  }
  if (result.hasActualTypeArguments()) {
    ArrayList typeArgs=(ArrayList)result.getActualTypeArguments();
    jClass=(JavaClass)typeArgs.get(0);
  }
  return jClass;
}

Fixed version (ground truth):
/** 
 * Return a given method's generic return type as a JavaClass.
 * @param meth
 * @return
 */
public JavaClass getGenericReturnType(JavaMethod meth){
  JavaClass result=meth.getReturnType();
  JavaClass jClass=null;
  if (result == null) {
    return null;
  }
  Collection args=result.getActualTypeArguments();
  if (args.size() > 0) {
    jClass=(JavaClass)args.iterator().next();
  }
  return jClass;
}
Program: 64637
Project: 64637
Buggy source:
/** 
 * Convenience method to determine if two JavaClass instances are equal.
 * @param classA
 * @param classB
 * @return
 */
private boolean areClassesEqual(JavaClass classA,JavaClass classB){
  if (classA == classB) {
    return true;
  }
  if (!(classA.getQualifiedName().equals(classB.getQualifiedName()))) {
    return false;
  }
  if (classA.getActualTypeArguments() != null) {
    if (classB.getActualTypeArguments() == null) {
      return false;
    }
    if (classA.getActualTypeArguments().size() != classB.getActualTypeArguments().size()) {
      return false;
    }
    for (int i=0; i < classA.getActualTypeArguments().size(); i++) {
      JavaClass nestedClassA=(JavaClass)classA.getActualTypeArguments().toArray()[i];
      JavaClass nestedClassB=(JavaClass)classB.getActualTypeArguments().toArray()[i];
      if (!areClassesEqual(nestedClassA,nestedClassB)) {
        return false;
      }
    }
    return true;
  }
  if (classB.getActualTypeArguments() == null) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Convenience method to determine if two JavaClass instances are equal.
 * @param classA
 * @param classB
 * @return
 */
private boolean areClassesEqual(JavaClass classA,JavaClass classB){
  if (classA == classB) {
    return true;
  }
  if (!(classA.getQualifiedName().equals(classB.getQualifiedName()))) {
    return false;
  }
  Collection classAargs=classA.getActualTypeArguments();
  Collection classBargs=classB.getActualTypeArguments();
  if (classAargs != null) {
    if (classBargs == null) {
      return false;
    }
    if (classAargs.size() != classBargs.size()) {
      return false;
    }
    Iterator classAargsIter=classAargs.iterator();
    Iterator classBargsIter=classBargs.iterator();
    while (classAargsIter.hasNext()) {
      JavaClass nestedClassA=(JavaClass)classAargsIter.next();
      JavaClass nestedClassB=(JavaClass)classBargsIter.next();
      if (!areClassesEqual(nestedClassA,nestedClassB)) {
        return false;
      }
    }
    return true;
  }
  if (classBargs == null) {
    return true;
  }
  return false;
}
Program: 64638
Project: 64638
Buggy source:
public boolean hasActualTypeArguments(){
  if (jType instanceof ParameterizedType) {
    ParameterizedType pType=(ParameterizedType)jType;
    if (pType.getActualTypeArguments() != null && pType.getActualTypeArguments().length > 0) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
public boolean hasActualTypeArguments(){
  return getActualTypeArguments().size() > 0;
}
Program: 64639
Project: 64639
Buggy source:
public JSONFormattedWriterRecord(){
  numberOfTabs=0;
  complexType=true;
  isLastEventText=false;
  space="String_Node_Str";
}

Fixed version (ground truth):
public JSONFormattedWriterRecord(Writer writer,String callbackName){
  this(writer);
  setCallbackName(callbackName);
}
Program: 64640
Project: 64640
Buggy source:
public JSONWriterRecord(){
  super();
  space=XMLConstants.EMPTY_STRING;
}

Fixed version (ground truth):
public JSONWriterRecord(Writer writer,String callbackName){
  this(writer);
  setCallbackName(callbackName);
}
Program: 64641
Project: 64641
Buggy source:
@Override public void endCollection(){
  try {
    if (levels.size() == 1) {
      writer.write(']');
    }
 else {
      Level position=levels.peek();
      if (position != null && position.isCollection() && !position.isEmptyCollection()) {
        writer.write(']');
      }
    }
    levels.peek().setCollection(false);
  }
 catch (  IOException e) {
    throw XMLMarshalException.marshalException(e);
  }
}

Fixed version (ground truth):
@Override public void endCollection(){
  try {
    if (levels.size() == 1) {
      writer.write(']');
      endCallback();
    }
 else {
      Level position=levels.peek();
      if (position != null && position.isCollection() && !position.isEmptyCollection()) {
        writer.write(']');
      }
    }
    levels.peek().setCollection(false);
  }
 catch (  IOException e) {
    throw XMLMarshalException.marshalException(e);
  }
}
Program: 64642
Project: 64642
Buggy source:
@Override public void startCollection(){
  if (levels.isEmpty()) {
    try {
      writer.write('[');
      levels.push(new Level(true,false));
    }
 catch (    IOException e) {
      throw XMLMarshalException.marshalException(e);
    }
  }
 else {
    levels.peek().setCollection(true);
    levels.peek().setEmptyCollection(true);
  }
}

Fixed version (ground truth):
@Override public void startCollection(){
  if (levels.isEmpty()) {
    try {
      startCallback();
      writer.write('[');
      levels.push(new Level(true,false));
    }
 catch (    IOException e) {
      throw XMLMarshalException.marshalException(e);
    }
  }
 else {
    levels.peek().setCollection(true);
    levels.peek().setEmptyCollection(true);
  }
}
Program: 64643
Project: 64643
Buggy source:
/** 
 * bug 366179 : test Tuple.get(string, Type) validation
 */
public void testTupleStringTypeValidation(){
  EntityManager em=createEntityManager();
  CriteriaBuilder qb=em.getCriteriaBuilder();
  CriteriaQuery<Tuple> criteria=qb.createTupleQuery();
  Root<Employee> emp=criteria.from(Employee.class);
  criteria.multiselect(emp.get("String_Node_Str").alias("String_Node_Str"),emp.get("String_Node_Str").alias("String_Node_Str"));
  criteria.where(qb.isNotNull(emp.get("String_Node_Str")));
  TypedQuery<Tuple> query=em.createQuery(criteria);
  List<Tuple> list=query.getResultList();
  Tuple row=list.get(0);
  row.get("String_Node_Str",String.class);
  try {
    Object result=row.get("String_Node_Str",java.sql.Date.class);
    this.fail("String_Node_Str" + result);
  }
 catch (  IllegalArgumentException iae) {
  }
}

Fixed version (ground truth):
/** 
 * bug 366179 : test Tuple.get(string, Type) validation
 */
public void testTupleStringTypeValidation(){
  EntityManager em=createEntityManager();
  CriteriaBuilder qb=em.getCriteriaBuilder();
  CriteriaQuery<Tuple> criteria=qb.createTupleQuery();
  Root<Employee> emp=criteria.from(Employee.class);
  criteria.multiselect(emp.get("String_Node_Str").alias("String_Node_Str"),emp.get("String_Node_Str").alias("String_Node_Str"));
  criteria.where(qb.isNotNull(emp.get("String_Node_Str")));
  TypedQuery<Tuple> query=em.createQuery(criteria);
  List<Tuple> list=query.getResultList();
  Tuple row=list.get(0);
  row.get("String_Node_Str",String.class);
  try {
    Object result=row.get("String_Node_Str",java.sql.Date.class);
    this.fail("String_Node_Str" + result);
  }
 catch (  IllegalArgumentException iae) {
  }
  closeEntityManager(em);
}
Program: 64644
Project: 64644
Buggy source:
/** 
 * bug 366182 : test Tuple.get(tuple) validation
 */
public void testTupleTupleValidation(){
  EntityManager em=createEntityManager();
  CriteriaBuilder qb=em.getCriteriaBuilder();
  CriteriaQuery<Tuple> criteria=qb.createTupleQuery();
  Root<Employee> emp=criteria.from(Employee.class);
  Path unusedTupleElement=emp.get("String_Node_Str");
  Path lastName=emp.get("String_Node_Str");
  criteria.multiselect(lastName,emp.get("String_Node_Str"));
  TypedQuery<Tuple> query=em.createQuery(criteria);
  List<Tuple> list=query.getResultList();
  Tuple row=list.get(0);
  row.get(lastName);
  try {
    Object result=row.get(unusedTupleElement);
    this.fail("String_Node_Str" + result);
  }
 catch (  IllegalArgumentException iae) {
  }
}

Fixed version (ground truth):
/** 
 * bug 366182 : test Tuple.get(tuple) validation
 */
public void testTupleTupleValidation(){
  EntityManager em=createEntityManager();
  CriteriaBuilder qb=em.getCriteriaBuilder();
  CriteriaQuery<Tuple> criteria=qb.createTupleQuery();
  Root<Employee> emp=criteria.from(Employee.class);
  Path unusedTupleElement=emp.get("String_Node_Str");
  Path lastName=emp.get("String_Node_Str");
  criteria.multiselect(lastName,emp.get("String_Node_Str"));
  TypedQuery<Tuple> query=em.createQuery(criteria);
  List<Tuple> list=query.getResultList();
  Tuple row=list.get(0);
  row.get(lastName);
  try {
    Object result=row.get(unusedTupleElement);
    this.fail("String_Node_Str" + result);
  }
 catch (  IllegalArgumentException iae) {
  }
  closeEntityManager(em);
}
Program: 64646
Project: 64646
Buggy source:
public CompoundSelectionImpl(Class javaType,Selection[] subSelections){
  super(javaType,null);
  this.subSelections=new ArrayList();
  for (  Selection sel : subSelections) {
    this.subSelections.add(sel);
  }
}

Fixed version (ground truth):
public CompoundSelectionImpl(Class javaType,Selection[] subSelections,boolean validate){
  super(javaType,null);
  this.subSelections=new ArrayList();
  for (  Selection sel : subSelections) {
    if (validate) {
      if (((SelectionImpl)sel).isCompoundSelection() && !((SelectionImpl)sel).isConstructor()) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{sel}));
      }
    }
    this.subSelections.add(sel);
  }
}
Program: 64647
Project: 64647
Buggy source:
public ConstructorSelectionImpl(Class javaType,Selection[] subSelections){
  super(javaType,subSelections);
}

Fixed version (ground truth):
public ConstructorSelectionImpl(Class javaType,Selection[] subSelections){
  super(javaType,subSelections,true);
}
Program: 64648
Project: 64648
Buggy source:
private int hasIndex(String xpathString){
  int index=-1;
  int startindex=xpathString.lastIndexOf('[');
  if ((startindex != -1) && (xpathString.lastIndexOf(']') != -1)) {
    StringTokenizer st=new StringTokenizer(xpathString,"String_Node_Str");
    String element=st.nextToken();
    while (st.hasMoreTokens()) {
      String indexString=st.nextToken();
      try {
        index=Integer.valueOf(indexString).intValue();
        setContainsIndex(true);
      }
 catch (      NumberFormatException e) {
        StringTokenizer st2=new StringTokenizer(indexString,"String_Node_Str");
        if (2 == st2.countTokens()) {
          XPathFragment xPathFragment=new XPathFragment(st2.nextToken());
          String value=st2.nextToken();
          value=value.substring(1,value.length() - 1);
          predicate=new XPathPredicate(xPathFragment,value);
        }
 else {
          setContainsIndex(true);
        }
        setShouldExecuteSelectNodes(true);
      }
    }
    shortName=element;
  }
 else {
    index=-1;
  }
  return index;
}

Fixed version (ground truth):
private int hasIndex(String xpathString){
  int index=-1;
  int startindex=xpathString.lastIndexOf('[');
  if ((startindex != -1) && (xpathString.lastIndexOf(']') != -1)) {
    StringTokenizer st=new StringTokenizer(xpathString,"String_Node_Str");
    String element=st.nextToken();
    while (st.hasMoreTokens()) {
      String indexString=st.nextToken();
      try {
        index=Integer.valueOf(indexString).intValue();
        setContainsIndex(true);
      }
 catch (      NumberFormatException e) {
        int equalsOffset=indexString.indexOf('=');
        if (equalsOffset >= 0) {
          XPathFragment xPathFragment=new XPathFragment(indexString.substring(0,equalsOffset));
          String value=indexString.substring(equalsOffset + 2,indexString.length() - 1);
          predicate=new XPathPredicate(xPathFragment,value);
        }
 else {
          setContainsIndex(true);
        }
        setShouldExecuteSelectNodes(true);
      }
    }
    shortName=element;
  }
 else {
    index=-1;
  }
  return index;
}
Program: 64650
Project: 64650
Buggy source:
/** 
 * ADVANCED: Return all registered descriptors.
 */
public Map<Class,ClassDescriptor> getDescriptors(){
  if (this.descriptors != null) {
    return this.descriptors;
  }
 else {
    return this.project.getDescriptors();
  }
}

Fixed version (ground truth):
/** 
 * ADVANCED: Return all registered descriptors.
 */
public Map<Class,ClassDescriptor> getDescriptors(){
  return this.project.getDescriptors();
}
Program: 64651
Project: 64651
Buggy source:
public void arrayEchoTest(){
  XMLUnmarshaller unmarshaller=xrService.getXMLContext().createUnmarshaller();
  Object pType=unmarshaller.unmarshal(new StringReader(MYTYPE_XML));
  Invocation invocation=new Invocation("String_Node_Str");
  invocation.setParameter("String_Node_Str",pType);
  Operation op=xrService.getOperation(invocation.getName());
  Object result=op.invoke(xrService,invocation);
  assertNotNull("String_Node_Str",result);
  Document doc=xmlPlatform.createDocument();
  XMLMarshaller marshaller=xrService.getXMLContext().createMarshaller();
  marshaller.marshal(result,doc);
  Document controlDoc=xmlParser.parse(new StringReader(MYTYPE_XML));
  assertTrue("String_Node_Str" + documentToString(controlDoc) + "String_Node_Str"+ documentToString(doc),comparer.isNodeEqual(controlDoc,doc));
}

Fixed version (ground truth):
@Test public void arrayEchoTest(){
  XMLUnmarshaller unmarshaller=xrService.getXMLContext().createUnmarshaller();
  Object pType=unmarshaller.unmarshal(new StringReader(MYTYPE_ARRAY_XML));
  Invocation invocation=new Invocation("String_Node_Str");
  invocation.setParameter("String_Node_Str",pType);
  Operation op=xrService.getOperation(invocation.getName());
  Object result=op.invoke(xrService,invocation);
  assertNotNull("String_Node_Str",result);
  Document doc=xmlPlatform.createDocument();
  XMLMarshaller marshaller=xrService.getXMLContext().createMarshaller();
  marshaller.marshal(result,doc);
  Document controlDoc=xmlParser.parse(new StringReader(MYTYPE_ARRAY_XML));
  assertTrue("String_Node_Str" + documentToString(controlDoc) + "String_Node_Str"+ documentToString(doc),comparer.isNodeEqual(controlDoc,doc));
}
Program: 64656
Project: 64656
Buggy source:
@AfterClass public static void tearDown(){
  if (ddlDrop) {
    runDdl(conn,DROP_EMP_TYPE_TABLE,ddlDebug);
    runDdl(conn,DROP_ADD_EMP_TYPE2_FUNC,ddlDebug);
    runDdl(conn,DROP_ADD_EMP_TYPE_PROC,ddlDebug);
    runDdl(conn,DROP_GET_EMP_TYPE_BY_ID_2_FUNC,ddlDebug);
    runDdl(conn,DROP_GET_EMP_TYPE_BY_ID_PROC,ddlDebug);
    runDdl(conn,DROP_EMP_TYPE,ddlDebug);
    runDdl(conn,DROP_PHONE_TYPE,ddlDebug);
  }
}

Fixed version (ground truth):
@AfterClass public static void tearDown(){
  if (ddlDrop) {
    runDdl(conn,DROP_EMP_TYPE_TABLE,ddlDebug);
    runDdl(conn,DROP_ADD_EMP_TYPE2_FUNC,ddlDebug);
    runDdl(conn,DROP_ADD_EMP_TYPE_PROC,ddlDebug);
    runDdl(conn,DROP_GET_EMP_TYPE_BY_ID_2_FUNC,ddlDebug);
    runDdl(conn,DROP_GET_EMP_TYPE_BY_ID_PROC,ddlDebug);
    runDdl(conn,DROP_EMP_TYPE,ddlDebug);
    runDdl(conn,DROP_PHONE_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE_BODY_USER_TYPE_INOUT,ddlDebug);
    runDdl(conn,DROP_PACKAGE_USER_TYPE_INOUT,ddlDebug);
    runDdl(conn,DROP_TYPE_MYTYPE_1_ARRAY,ddlDebug);
    runDdl(conn,DROP_TYPE_MYTYPE_1,ddlDebug);
  }
}
Program: 64659
Project: 64659
Buggy source:
protected void reportElementEvents(Element elem) throws SAXException {
  this.currentNode=elem;
  IndexedAttributeList attributes=buildAttributeList(elem);
  String qname;
  String lname=elem.getLocalName();
  if (lname == null) {
    lname=elem.getNodeName();
    qname=lname;
    handlePrefixedAttribute(elem);
  }
 else {
    qname=getQName(elem);
  }
  String namespaceUri=elem.getNamespaceURI();
  if (namespaceUri == null) {
    namespaceUri="String_Node_Str";
  }
  contentHandler.startElement(namespaceUri,lname,qname,attributes);
  handleChildNodes(elem.getChildNodes());
  contentHandler.endElement(namespaceUri,lname,qname);
  endPrefixMappings(elem);
}

Fixed version (ground truth):
protected void reportElementEvents(Element elem,String newUri,String newName) throws SAXException {
  this.currentNode=elem;
  IndexedAttributeList attributes=buildAttributeList(elem);
  String namespaceUri=null;
  String qname=null;
  String lname=null;
  if (newName == null) {
    lname=elem.getLocalName();
    if (lname == null) {
      lname=elem.getNodeName();
      qname=lname;
      handlePrefixedAttribute(elem);
    }
 else {
      qname=getQName(elem);
    }
    namespaceUri=elem.getNamespaceURI();
    if (namespaceUri == null) {
      namespaceUri="String_Node_Str";
    }
  }
 else {
    namespaceUri=newUri;
    lname=newName;
    qname=newName;
    if (namespaceUri != null && isNamespaceAware()) {
      NamespaceResolver tmpNR=new NamespaceResolver();
      tmpNR.setDOM(elem);
      String prefix=tmpNR.resolveNamespaceURI(namespaceUri);
      if (prefix == null || prefix.length() == 0) {
        String defaultNamespace=elem.getAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS);
        if (defaultNamespace == null) {
          prefix=tmpNR.generatePrefix();
          contentHandler.startPrefixMapping(prefix,namespaceUri);
        }
 else         if (defaultNamespace != namespaceUri) {
          prefix=tmpNR.generatePrefix();
          contentHandler.startPrefixMapping(prefix,namespaceUri);
        }
 else {
          prefix=XMLConstants.EMPTY_STRING;
        }
      }
      if (prefix != null && prefix.length() > 0) {
        qname=prefix + XMLConstants.COLON + qname;
      }
    }
  }
  contentHandler.startElement(namespaceUri,lname,qname,attributes);
  handleChildNodes(elem.getChildNodes());
  contentHandler.endElement(namespaceUri,lname,qname);
  endPrefixMappings(elem);
}
Program: 64660
Project: 64660
Buggy source:
public void parse(Node node) throws SAXException {
  if (null == contentHandler) {
    return;
  }
  Element rootNode=null;
  if (node.getNodeType() == Node.DOCUMENT_NODE) {
    rootNode=((Document)node).getDocumentElement();
  }
 else {
    rootNode=(Element)node;
  }
  processParentNamespaces(rootNode);
  startDocument();
  setupLocator(rootNode.getOwnerDocument());
  reportElementEvents(rootNode);
  endDocument();
}

Fixed version (ground truth):
public void parse(Node node) throws SAXException {
  parse(node,null,null);
}
Program: 64662
Project: 64662
Buggy source:
public void writeToEventWriter(Node dom,XMLEventWriter xew) throws XMLStreamException {
  Node currentNode=dom;
  if (dom.getNodeType() == Node.DOCUMENT_NODE) {
    Document doc=(Document)dom;
    xew.add(xmlEventFactory.createStartDocument(doc.getXmlEncoding(),doc.getXmlVersion()));
    currentNode=doc.getDocumentElement();
  }
  if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
    writeElement((Element)currentNode,xew);
  }
 else   if (currentNode.getNodeType() == Node.ATTRIBUTE_NODE) {
    Attr attribute=(Attr)currentNode;
    if (attribute.getPrefix() != null && attribute.getPrefix().equals(XMLConstants.XMLNS)) {
      xew.add(xmlEventFactory.createNamespace(attribute.getLocalName(),attribute.getValue()));
    }
 else {
      if (attribute.getPrefix() == null) {
        xew.add(xmlEventFactory.createAttribute(attribute.getName(),attribute.getValue()));
      }
 else {
        xew.add(xmlEventFactory.createAttribute(attribute.getPrefix(),attribute.getNamespaceURI(),attribute.getLocalName(),attribute.getValue()));
      }
    }
  }
 else   if (currentNode.getNodeType() == Node.TEXT_NODE) {
    xew.add(xmlEventFactory.createCharacters(((Text)currentNode).getNodeValue()));
  }
  if (dom.getNodeType() == Node.DOCUMENT_NODE) {
    xew.add(xmlEventFactory.createEndDocument());
  }
}

Fixed version (ground truth):
public void writeToEventWriter(Node dom,String uri,String name,XMLEventWriter xew) throws XMLStreamException {
  Node currentNode=dom;
  if (dom.getNodeType() == Node.DOCUMENT_NODE) {
    Document doc=(Document)dom;
    xew.add(xmlEventFactory.createStartDocument(doc.getXmlEncoding(),doc.getXmlVersion()));
    currentNode=doc.getDocumentElement();
  }
  if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
    writeElement((Element)currentNode,uri,name,xew);
  }
 else   if (currentNode.getNodeType() == Node.ATTRIBUTE_NODE) {
    Attr attribute=(Attr)currentNode;
    if (attribute.getPrefix() != null && attribute.getPrefix().equals(XMLConstants.XMLNS)) {
      xew.add(xmlEventFactory.createNamespace(attribute.getLocalName(),attribute.getValue()));
    }
 else {
      if (attribute.getPrefix() == null) {
        xew.add(xmlEventFactory.createAttribute(attribute.getName(),attribute.getValue()));
      }
 else {
        xew.add(xmlEventFactory.createAttribute(attribute.getPrefix(),attribute.getNamespaceURI(),attribute.getLocalName(),attribute.getValue()));
      }
    }
  }
 else   if (currentNode.getNodeType() == Node.TEXT_NODE) {
    xew.add(xmlEventFactory.createCharacters(((Text)currentNode).getNodeValue()));
  }
  if (dom.getNodeType() == Node.DOCUMENT_NODE) {
    xew.add(xmlEventFactory.createEndDocument());
  }
}