Missing close() in DataTranscoder.java causes issues with fcsh.exe: embedded files remain locked
I have this program that runs fcsh.exe and I am running in a problem with files embedded as binary data, e.g.:
[Embed(source='bla.dat', mimeType='application/octet-stream')]
private const Bla:Class;
Randomly after compiling, the file remains locked, i.e. fcsh.exe still holds the write lock on the file bla.dat.
The random part had me think this is probably due to the open file object in java not being closed before becoming unreferenced, and so the file remains locked until garbage collection occurs.
After digging in, I found this piece of code in DataTranscoder.java which seems to be missing a .close() call:
public static void loadData(TranscodingResults asset)
throws TranscoderException
{
DefineBinaryData defineBinaryData = new DefineBinaryData();
try
{
BufferedInputStream in = new BufferedInputStream( asset.assetSource.getInputStream() );
int size = (int) asset.assetSource.size();
defineBinaryData.data = new byte[size];
int r = 0;
while (r < size)
{
int result = in.read( defineBinaryData.data, r, size - r );
if (result == -1)
break;
}
asset.defineTag = defineBinaryData;
}
catch (Exception e)
{
throw new AbstractTranscoder.UnableToReadSource( asset.assetSource.getName() );
}
}Furthermore, I am not having any problems with embedded audio files, and indeed, SoundTranscoder.java has the .close() call:
public TranscodingResults doTranscode( PathResolver context, SymbolTable symbolTable,
Map<String, Object> args, String className, boolean generateSource )
throws TranscoderException
{
TranscodingResults results = new TranscodingResults( resolveSource( context, args ));
String newName = (String) args.get( Transcoder.NEWNAME );
results.defineTag = mp3(results.assetSource, newName);
if (generateSource)
generateSource( results, className, args );
return results;
}
private DefineSound mp3(VirtualFile source, String symbolName)
throws TranscoderException
{
InputStream in = null;
byte[] sound = null;
try
{
int size = (int) source.size();
in = source.getInputStream();
sound = readFully(in, size);
}
catch (IOException ex)
{
throw new AbstractTranscoder.ExceptionWhileTranscoding( ex );
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (IOException ex)
{
}
}
}Should I file a bug about this? If yes, in what system?
Thanks,
Ludovic
