Buggy code:
private void createSnapshot ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void deregisterImage ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void createImage ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void registerImage ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void modifyImageAttribute ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private EC2ModifyImageAttribute addLaunchPermImageAttribute ( HttpServletRequest request , EC2ModifyImageAttribute ec2request ) { } private void resetImageAttribute ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void runInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void rebootInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void startInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void stopInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void terminateInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeAvailabilityZones ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeImages ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeImageAttribute ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeInstances ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeSubnets ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeAddresses ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void allocateAddress ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void releaseAddress ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void associateAddress ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void disassociateAddress ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeSecurityGroups ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeInstanceAttribute ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void modifyInstanceAttribute ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeSnapshots ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void describeVolumes ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private EC2Filter [ ] extractFilters ( HttpServletRequest request ) { } private void describeKeyPairs ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void importKeyPair ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void createKeyPair ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void deleteKeyPair ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void getPasswordData ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void createTags ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private void deleteTags ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private EC2Tags createTagsRequest ( HttpServletRequest request , HttpServletResponse response ) throws IOException { } private void describeTags ( HttpServletRequest request , HttpServletResponse response ) throws IOException , XMLStreamException , ADBException { } private Pair < Boolean , HttpServletRequest > authenticateRequest ( HttpServletRequest request , HttpServletResponse response ) throws IOException , ClassNotFoundException , IllegalAccessException , InstantiationException , SignatureException , SQLException , ParseException { } private static final List VALID_CHARACTERS = Arrays . asList ( '%' ) ; private static boolean needsUrlEncode ( final String decode ) { } private String urlEncode ( String item , boolean encode ) { } private boolean hasSignatureExpired ( String timeStamp ) { } private static void endResponse ( HttpServletResponse response , String content ) { } private void logRequest ( HttpServletRequest request ) { } private void faultResponse ( HttpServletResponse response , String errorCode , String errorMessage ) { } private void serializeResponse ( HttpServletResponse response , ADBBean EC2Response ) throws IOException , XMLStreamException , ADBException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; XMLStreamWriter xmlWriter = xmlOutFactory . createXMLStreamWriter ( out ) ; MTOMAwareXMLSerializer mtomWriter = new MTOMAwareXMLSerializer ( xmlWriter ) ; mtomWriter . setDefaultNamespace ( ( ( RequestContext . current ( ) . getNamespace ( ) ) == null ? null : RequestContext . current ( ) . getNamespace ( ) . getUrl ( ) ) ) ; EC2Response . serialize ( null , factory , mtomWriter ) ; xmlWriter . flush ( ) ; String xmlResponse = out . toString ( ) . replace ( Namespace . getCurrent ( ) . getUrl ( ) , RequestContext . current ( ) . getNamespace ( ) . getUrl ( ) ) ; xmlWriter . close ( ) ; xmlResponse = xmlResponse . replace ( "<seq2seq4repair_space>xmlns:ns1=" , "<seq2seq4repair_space>xmlns=" ) . replaceAll ( "<ns1:" , "<" ) . replaceAll ( "<//ns1:" , "<//" ) ; response . setContentType ( "text//xml;<seq2seq4repair_space>charset=UTF-8" ) ; xmlResponse = "<?xml<seq2seq4repair_space>version=\"1.0\"<seq2seq4repair_space>encoding=\"UTF-8\"?>\n" + xmlResponse ; <START_BUG> int contentLength = xmlResponse . length ( ) ; <END_BUG> response . setContentLength ( contentLength ) ; response . getWriter ( ) . write ( xmlResponse ) ; response . getWriter ( ) . flush ( ) ; response . getWriter ( ) . close ( ) ; } }

Fix:
int contentLength = xmlResponse . getBytes ( "UTF-8" ) . length ;