private List< String > extractMetaDataLines() { final ArrayList< String > metaDataLines = new ArrayList< String >(); int currentLineIndex = 0; int start = 0; int end = 0;
for ( final String line : getLines() ) { if ( line.contains( METADATA_TAG ) ) { if ( line.contains( "</" ) ) { end = currentLineIndex - ( getLines().get( currentLineIndex - 1 ).contains( "]]>" ) ? 1 : 0 ); if ( line.contains( "<fx" ) || line.contains( "<mx" ) ) { start = end; } break; } if ( line.contains( "<" ) ) { start = currentLineIndex + ( getLines().get( currentLineIndex + 1 ).contains( "CDATA[" ) ? 2 : 1 ); } } currentLineIndex++; } metaDataLines.addAll( getLines().subList( start, end ) ); return metaDataLines; } The above code is wrong in many ways, but I don't know what would be the best way to fix it. The problem with it, essentially, is that if the metadata has just one line and was declared as CData (the most popular case) this code throw because it will put the start index after the end index. Ideally, this whole code should read MXML file as an XML document and not try to read it line-by line, certainly not in such reckless way... But even if for some reason that is not possible, then it would be proper to search for opening metadata tag, then, search for the CData opening token, and only if present, search for the end CData token, and then search for the metadata closing tag. Best, Oleg