Skip to content

Commit

Permalink
HSEARCH-3425 Warnings: use try-with-resources where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Feb 8, 2019
1 parent 8037488 commit ee4dff1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Expand Up @@ -41,26 +41,20 @@ private AnalyzerUtils() {
* @throws SearchException if a problem occurs when analyzing the sortable field's value.
*/
public static String normalize(Analyzer analyzer, String fieldName, String text) {
final TokenStream stream = analyzer.tokenStream( fieldName, new StringReader( text ) );
try {
try {
String firstToken = null;
CharTermAttribute term = stream.addAttribute( CharTermAttribute.class );
stream.reset();
try ( TokenStream stream = analyzer.tokenStream( fieldName, new StringReader( text ) ) ) {
String firstToken = null;
CharTermAttribute term = stream.addAttribute( CharTermAttribute.class );
stream.reset();
if ( stream.incrementToken() ) {
firstToken = new String( term.buffer(), 0, term.length() );
if ( stream.incrementToken() ) {
firstToken = new String( term.buffer(), 0, term.length() );
if ( stream.incrementToken() ) {
log.multipleTermsDetectedDuringNormalization( fieldName );
}
else {
stream.end();
}
log.multipleTermsDetectedDuringNormalization( fieldName );
}
else {
stream.end();
}
return firstToken;
}
finally {
stream.close();
}
return firstToken;
}
catch (SearchException | IOException e) {
throw log.couldNotNormalizeField( fieldName, e );
Expand Down
Expand Up @@ -149,10 +149,9 @@ private void loadAllIdentifiers(final StatelessSession session) throws Interrupt
.setCacheable( false )
.setFetchSize( idFetchSize );

ScrollableResults results = criteria.scroll( ScrollMode.FORWARD_ONLY );
ArrayList<Serializable> destinationList = new ArrayList<>( batchSize );
long counter = 0;
try {
try ( ScrollableResults results = criteria.scroll( ScrollMode.FORWARD_ONLY ) ) {
while ( results.next() ) {
Serializable id = (Serializable) results.get( 0 );
destinationList.add( id );
Expand All @@ -173,9 +172,6 @@ private void loadAllIdentifiers(final StatelessSession session) throws Interrupt
}
}
}
finally {
results.close();
}
enqueueList( destinationList );
}

Expand Down

0 comments on commit ee4dff1

Please sign in to comment.