You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Carsten Schnober <sc...@ids-mannheim.de> on 2012/11/21 14:50:37 UTC

Potential Resource Leak warning in Analyer.createComponents()

Hi,
I use a custom analyzer and tokenizer. The analyzer is very basic and it
merely comprises the method createComponents():

-------------------------------------------------------------
@Override
protected TokenStreamComponents createComponents(String fieldName,
Reader reader) {
  return new TokenStreamComponents(new KoraTokenizer(reader));
}
-------------------------------------------------------------

Eclipse gives me a warning though "potential resource leak" because the
tokenizer is never closed. This is clearly true but is it not desirable
either, is it?
To get rid of the warning, I had experimentally changed the method to this:

Tokenizer source = new KoraTokenizer(reader);
TokenStreamComponents ts = new TokenStreamComponents(source);
source.close();
return ts;

This yields what I had expected, namely a null TokenStream during
analysis. So regarding the results, I think the initial version is
right, but I am suspicious against the resource leak warning. How
serious is it?
Best,
Carsten


-- 
Institut für Deutsche Sprache | http://www.ids-mannheim.de
Projekt KorAP                 | http://korap.ids-mannheim.de
Tel. +49-(0)621-43740789      | schnober@ids-mannheim.de
Korpusanalyseplattform der nächsten Generation
Next Generation Corpus Analysis Platform

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Potential Resource Leak warning in Analyer.createComponents()

Posted by Uwe Schindler <uw...@thetaphi.de>.
Disable this warning, your workaround is worse than the warning.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Carsten Schnober [mailto:schnober@ids-mannheim.de]
> Sent: Wednesday, November 21, 2012 2:51 PM
> To: java-user
> Subject: Potential Resource Leak warning in Analyer.createComponents()
> 
> Hi,
> I use a custom analyzer and tokenizer. The analyzer is very basic and it merely
> comprises the method createComponents():
> 
> -------------------------------------------------------------
> @Override
> protected TokenStreamComponents createComponents(String fieldName,
> Reader reader) {
>   return new TokenStreamComponents(new KoraTokenizer(reader)); }
> -------------------------------------------------------------
> 
> Eclipse gives me a warning though "potential resource leak" because the
> tokenizer is never closed. This is clearly true but is it not desirable either, is it?
> To get rid of the warning, I had experimentally changed the method to this:
> 
> Tokenizer source = new KoraTokenizer(reader); TokenStreamComponents ts
> = new TokenStreamComponents(source); source.close(); return ts;
> 
> This yields what I had expected, namely a null TokenStream during analysis.
> So regarding the results, I think the initial version is right, but I am suspicious
> against the resource leak warning. How serious is it?
> Best,
> Carsten
> 
> 
> --
> Institut für Deutsche Sprache | http://www.ids-mannheim.de
> Projekt KorAP                 | http://korap.ids-mannheim.de
> Tel. +49-(0)621-43740789      | schnober@ids-mannheim.de
> Korpusanalyseplattform der nächsten Generation Next Generation Corpus
> Analysis Platform
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org