Buggy code:
for ( int i = 0 ; i < ( attrs . getLength ( ) ) ; i ++ ) { String key = attrs . getName ( i ) ; String value = attrs . getValue ( i ) ; if ( key . equals ( "default" ) ) { def = value ; } else if ( key . equals ( "name" ) ) { name = value ; } else if ( key . equals ( "id" ) ) { id = value ; } else if ( key . equals ( "basedir" ) ) { baseDir = value ; } else { throw new SAXParseException ( ( ( "Unexpected<seq2seq4repair_space>attribute<seq2seq4repair_space>\"" + ( attrs . getName ( i ) ) ) + "\"" ) , locator ) ; } } project . setDefaultTarget ( def ) ; project . setName ( name ) ; if ( name != null ) project . addReference ( name , project ) ; if ( id != null ) project . addReference ( id , project ) ; if ( ( project . getProperty ( "basedir" ) ) != null ) { project . setBasedir ( project . getProperty ( "basedir" ) ) ; } else { project . setBasedir ( baseDir ) ; } } public void startElement ( String name , AttributeList attrs ) throws SAXParseException { } private void handleTaskdef ( String name , AttributeList attrs ) throws SAXParseException { } private void handleProperty ( String name , AttributeList attrs ) throws SAXParseException { } private void handleTarget ( String tag , AttributeList attrs ) throws SAXParseException { } } private class TargetHandler extends ProjectHelper . AbstractHandler { private Target target ; public TargetHandler ( DocumentHandler parentHandler ) { } public void init ( String tag , AttributeList attrs ) throws SAXParseException { String name = null ; String depends = "" ; String cond = null ; String id = null ; for ( int i = 0 ; i < ( attrs . getLength ( ) ) ; i ++ ) { String key = attrs . getName ( i ) ; String value = attrs . getValue ( i ) ; if ( key . equals ( "name" ) ) { name = value ; } else if ( key . equals ( "depends" ) ) { depends = value ; } else if ( key . equals ( "if" ) ) { cond = value ; } else if ( key . equals ( "id" ) ) { id = value ; } else { throw new SAXParseException ( ( ( "Unexpected<seq2seq4repair_space>attribute<seq2seq4repair_space>\"" + key ) + "\"" ) , locator ) ; } } if ( name == null ) { throw new SAXParseException ( "target<seq2seq4repair_space>element<seq2seq4repair_space>appears<seq2seq4repair_space>without<seq2seq4repair_space>a<seq2seq4repair_space>name<seq2seq4repair_space>attribute" , locator ) ; } target = new Target ( ) ; target . setName ( name ) ; target . setCondition ( cond ) ; project . addTarget ( name , target ) ; if ( ( id != null ) && ( ! ( id . equals ( "" ) ) ) ) project . addReference ( id , target ) ; if ( ( depends . length ( ) ) > 0 ) { StringTokenizer tok = new StringTokenizer ( depends , "," , false ) ; while ( tok . hasMoreTokens ( ) ) { target . addDependency ( tok . nextToken ( ) . trim ( ) ) ; } } } public void startElement ( String name , AttributeList attrs ) throws SAXParseException { } } private class TaskHandler extends ProjectHelper . AbstractHandler { private Target target ; private Task task ; public TaskHandler ( DocumentHandler parentHandler , Target target ) { } public void init ( String tag , AttributeList attrs ) throws SAXParseException { task = project . createTask ( tag ) ; configure ( task , attrs ) ; task . setLocation ( new Location ( buildFile . toString ( ) , locator . getLineNumber ( ) , locator . getColumnNumber ( ) ) ) ; task . init ( ) ; if ( ( target ) != null ) { <START_BUG> task . setTarget ( target ) ; <END_BUG> target . addTask ( task ) ; } } public void characters ( char [ ] buf , int start , int end ) throws SAXParseException { } public void startElement ( String name , AttributeList attrs ) throws SAXParseException { } } private class NestedElementHandler extends ProjectHelper . AbstractHandler { private DocumentHandler parentHandler ; private Object target ; private Object child ; public NestedElementHandler ( DocumentHandler parentHandler , Object target ) { } public void init ( String propType , AttributeList attrs ) throws SAXParseException { Class targetClass = target . getClass ( ) ; String methodName = ( "create" + ( Character . toUpperCase ( propType . charAt ( 0 ) ) ) ) + ( propType . substring ( 1 ) ) ; try { Method addProp = targetClass . getMethod ( methodName , new Class [ ] { } ) ; child = addProp . invoke ( target , new Object [ ] { } ) ; configure ( child , attrs ) ; } catch ( NoSuchMethodException exc ) { throw new SAXParseException ( ( ( ( targetClass + "<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>support<seq2seq4repair_space>nested<seq2seq4repair_space>" ) + propType ) + "<seq2seq4repair_space>properties" ) , locator ) ; } catch ( InvocationTargetException exc ) { throw new SAXParseException ( exc . getMessage ( ) , locator ) ; } catch ( IllegalAccessException exc ) { throw new SAXParseException ( exc . getMessage ( ) , locator ) ; } } public void startElement ( String name , AttributeList attrs ) throws SAXParseException { } } private void configure ( Object target , AttributeList attrs ) throws BuildException { } public static String replaceProperties ( String value , Hashtable keys ) throws BuildException { } private static SAXParserFactory getParserFactory ( ) { } }

Fix:
task . setOwningTarget ( target ) ;