Program: 167853
Project: 167853
Buggy source:
protected void writeSocketBindingGroup(XMLExtendedStreamWriter writer,ModelNode bindingGroup,boolean fromServer) throws XMLStreamException {
  writer.writeStartElement(Element.SOCKET_BINDING_GROUP.getLocalName());
  SocketBindingGroupResourceDefinition.NAME.marshallAsAttribute(bindingGroup,writer);
  SocketBindingGroupResourceDefinition.DEFAULT_INTERFACE.marshallAsAttribute(bindingGroup,writer);
  if (fromServer) {
    SocketBindingGroupResourceDefinition.PORT_OFFSET.marshallAsAttribute(bindingGroup,writer);
  }
  if (!fromServer) {
    SocketBindingGroupResourceDefinition.INCLUDES.marshallAsElement(bindingGroup,writer);
  }
  if (bindingGroup.hasDefined(SOCKET_BINDING)) {
    ModelNode bindings=bindingGroup.get(SOCKET_BINDING);
    for (    String bindingName : bindings.keys()) {
      ModelNode binding=bindings.get(bindingName);
      writer.writeStartElement(Element.SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,bindingName);
      ModelNode attr=binding.get(INTERFACE);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.INTERFACE,attr.asString());
      }
      attr=binding.get(PORT);
      writeAttribute(writer,Attribute.PORT,attr.asString());
      attr=binding.get(FIXED_PORT);
      if (attr.isDefined() && attr.asBoolean()) {
        writeAttribute(writer,Attribute.FIXED_PORT,attr.asString());
      }
      attr=binding.get(MULTICAST_ADDRESS);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.MULTICAST_ADDRESS,attr.asString());
      }
      attr=binding.get(MULTICAST_PORT);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.MULTICAST_PORT,attr.asString());
      }
      attr=binding.get(CLIENT_MAPPINGS);
      if (attr.isDefined()) {
        for (        ModelNode mapping : attr.asList()) {
          writer.writeEmptyElement(Element.CLIENT_MAPPING.getLocalName());
          attr=mapping.get(SOURCE_NETWORK);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.SOURCE_NETWORK,attr.asString());
          }
          attr=mapping.get(DESTINATION_ADDRESS);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_ADDRESS,attr.asString());
          }
          attr=mapping.get(DESTINATION_PORT);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_PORT,attr.asString());
          }
        }
      }
      writer.writeEndElement();
      attr=binding.get(CLIENT_MAPPINGS);
      if (attr.isDefined()) {
        for (        ModelNode mapping : attr.asList()) {
          writer.writeEmptyElement(Element.CLIENT_MAPPING.getLocalName());
          attr=binding.get(SOURCE_NETWORK);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.SOURCE_NETWORK,attr.asString());
          }
          attr=binding.get(DESTINATION_ADDRESS);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_ADDRESS,attr.asString());
          }
          attr=binding.get(DESTINATION_PORT);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_PORT,attr.asString());
          }
        }
      }
    }
  }
  if (bindingGroup.hasDefined(LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING)) {
    final ModelNode localDestinationOutboundSocketBindings=bindingGroup.get(LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING);
    for (    final String outboundSocketBindingName : localDestinationOutboundSocketBindings.keys()) {
      final ModelNode outboundSocketBinding=localDestinationOutboundSocketBindings.get(outboundSocketBindingName);
      writer.writeStartElement(Element.OUTBOUND_SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,outboundSocketBindingName);
      if (outboundSocketBinding.hasDefined(SOURCE_PORT)) {
        final String sourcePort=outboundSocketBinding.get(SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.SOURCE_PORT,sourcePort);
      }
      if (outboundSocketBinding.hasDefined(SOURCE_INTERFACE)) {
        final String sourceInterface=outboundSocketBinding.get(SOURCE_INTERFACE).asString();
        writeAttribute(writer,Attribute.SOURCE_INTERFACE,sourceInterface);
      }
      if (outboundSocketBinding.hasDefined(FIXED_SOURCE_PORT)) {
        final String fixedSourcePort=outboundSocketBinding.get(FIXED_SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.FIXED_SOURCE_PORT,fixedSourcePort);
      }
      writer.writeStartElement(Element.LOCAL_DESTINATION.getLocalName());
      final ModelNode socketBindingRef=outboundSocketBinding.get(SOCKET_BINDING_REF);
      writeAttribute(writer,Attribute.SOCKET_BINDING_REF,socketBindingRef.asString());
      writer.writeEndElement();
      writer.writeEndElement();
    }
  }
  if (bindingGroup.hasDefined(REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING)) {
    final ModelNode remoteDestinationOutboundSocketBindings=bindingGroup.get(REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING);
    for (    final String outboundSocketBindingName : remoteDestinationOutboundSocketBindings.keys()) {
      final ModelNode outboundSocketBinding=remoteDestinationOutboundSocketBindings.get(outboundSocketBindingName);
      writer.writeStartElement(Element.OUTBOUND_SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,outboundSocketBindingName);
      if (outboundSocketBinding.hasDefined(SOURCE_PORT)) {
        final String sourcePort=outboundSocketBinding.get(SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.SOURCE_PORT,sourcePort);
      }
      if (outboundSocketBinding.hasDefined(SOURCE_INTERFACE)) {
        final String sourceInterface=outboundSocketBinding.get(SOURCE_INTERFACE).asString();
        writeAttribute(writer,Attribute.SOURCE_INTERFACE,sourceInterface);
      }
      if (outboundSocketBinding.hasDefined(FIXED_SOURCE_PORT)) {
        final String fixedSourcePort=outboundSocketBinding.get(FIXED_SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.FIXED_SOURCE_PORT,fixedSourcePort);
      }
      writer.writeStartElement(Element.REMOTE_DESTINATION.getLocalName());
      final ModelNode host=outboundSocketBinding.get(HOST);
      writeAttribute(writer,Attribute.HOST,host.asString());
      final ModelNode destPort=outboundSocketBinding.get(PORT);
      writeAttribute(writer,Attribute.PORT,destPort.asString());
      writer.writeEndElement();
      writer.writeEndElement();
    }
  }
  writer.writeEndElement();
}

Fixed version (ground truth):
protected void writeSocketBindingGroup(XMLExtendedStreamWriter writer,ModelNode bindingGroup,boolean fromServer) throws XMLStreamException {
  writer.writeStartElement(Element.SOCKET_BINDING_GROUP.getLocalName());
  SocketBindingGroupResourceDefinition.NAME.marshallAsAttribute(bindingGroup,writer);
  SocketBindingGroupResourceDefinition.DEFAULT_INTERFACE.marshallAsAttribute(bindingGroup,writer);
  if (fromServer) {
    SocketBindingGroupResourceDefinition.PORT_OFFSET.marshallAsAttribute(bindingGroup,writer);
  }
  if (!fromServer) {
    SocketBindingGroupResourceDefinition.INCLUDES.marshallAsElement(bindingGroup,writer);
  }
  if (bindingGroup.hasDefined(SOCKET_BINDING)) {
    ModelNode bindings=bindingGroup.get(SOCKET_BINDING);
    for (    String bindingName : bindings.keys()) {
      ModelNode binding=bindings.get(bindingName);
      writer.writeStartElement(Element.SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,bindingName);
      ModelNode attr=binding.get(INTERFACE);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.INTERFACE,attr.asString());
      }
      attr=binding.get(PORT);
      writeAttribute(writer,Attribute.PORT,attr.asString());
      attr=binding.get(FIXED_PORT);
      if (attr.isDefined() && attr.asBoolean()) {
        writeAttribute(writer,Attribute.FIXED_PORT,attr.asString());
      }
      attr=binding.get(MULTICAST_ADDRESS);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.MULTICAST_ADDRESS,attr.asString());
      }
      attr=binding.get(MULTICAST_PORT);
      if (attr.isDefined()) {
        writeAttribute(writer,Attribute.MULTICAST_PORT,attr.asString());
      }
      attr=binding.get(CLIENT_MAPPINGS);
      if (attr.isDefined()) {
        for (        ModelNode mapping : attr.asList()) {
          writer.writeEmptyElement(Element.CLIENT_MAPPING.getLocalName());
          attr=mapping.get(SOURCE_NETWORK);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.SOURCE_NETWORK,attr.asString());
          }
          attr=mapping.get(DESTINATION_ADDRESS);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_ADDRESS,attr.asString());
          }
          attr=mapping.get(DESTINATION_PORT);
          if (attr.isDefined()) {
            writeAttribute(writer,Attribute.DESTINATION_PORT,attr.asString());
          }
        }
      }
      writer.writeEndElement();
    }
  }
  if (bindingGroup.hasDefined(LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING)) {
    final ModelNode localDestinationOutboundSocketBindings=bindingGroup.get(LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING);
    for (    final String outboundSocketBindingName : localDestinationOutboundSocketBindings.keys()) {
      final ModelNode outboundSocketBinding=localDestinationOutboundSocketBindings.get(outboundSocketBindingName);
      writer.writeStartElement(Element.OUTBOUND_SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,outboundSocketBindingName);
      if (outboundSocketBinding.hasDefined(SOURCE_PORT)) {
        final String sourcePort=outboundSocketBinding.get(SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.SOURCE_PORT,sourcePort);
      }
      if (outboundSocketBinding.hasDefined(SOURCE_INTERFACE)) {
        final String sourceInterface=outboundSocketBinding.get(SOURCE_INTERFACE).asString();
        writeAttribute(writer,Attribute.SOURCE_INTERFACE,sourceInterface);
      }
      if (outboundSocketBinding.hasDefined(FIXED_SOURCE_PORT)) {
        final String fixedSourcePort=outboundSocketBinding.get(FIXED_SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.FIXED_SOURCE_PORT,fixedSourcePort);
      }
      writer.writeStartElement(Element.LOCAL_DESTINATION.getLocalName());
      final ModelNode socketBindingRef=outboundSocketBinding.get(SOCKET_BINDING_REF);
      writeAttribute(writer,Attribute.SOCKET_BINDING_REF,socketBindingRef.asString());
      writer.writeEndElement();
      writer.writeEndElement();
    }
  }
  if (bindingGroup.hasDefined(REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING)) {
    final ModelNode remoteDestinationOutboundSocketBindings=bindingGroup.get(REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING);
    for (    final String outboundSocketBindingName : remoteDestinationOutboundSocketBindings.keys()) {
      final ModelNode outboundSocketBinding=remoteDestinationOutboundSocketBindings.get(outboundSocketBindingName);
      writer.writeStartElement(Element.OUTBOUND_SOCKET_BINDING.getLocalName());
      writeAttribute(writer,Attribute.NAME,outboundSocketBindingName);
      if (outboundSocketBinding.hasDefined(SOURCE_PORT)) {
        final String sourcePort=outboundSocketBinding.get(SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.SOURCE_PORT,sourcePort);
      }
      if (outboundSocketBinding.hasDefined(SOURCE_INTERFACE)) {
        final String sourceInterface=outboundSocketBinding.get(SOURCE_INTERFACE).asString();
        writeAttribute(writer,Attribute.SOURCE_INTERFACE,sourceInterface);
      }
      if (outboundSocketBinding.hasDefined(FIXED_SOURCE_PORT)) {
        final String fixedSourcePort=outboundSocketBinding.get(FIXED_SOURCE_PORT).asString();
        writeAttribute(writer,Attribute.FIXED_SOURCE_PORT,fixedSourcePort);
      }
      writer.writeStartElement(Element.REMOTE_DESTINATION.getLocalName());
      final ModelNode host=outboundSocketBinding.get(HOST);
      writeAttribute(writer,Attribute.HOST,host.asString());
      final ModelNode destPort=outboundSocketBinding.get(PORT);
      writeAttribute(writer,Attribute.PORT,destPort.asString());
      writer.writeEndElement();
      writer.writeEndElement();
    }
  }
  writer.writeEndElement();
}