Skip to content

Commit

Permalink
HSEARCH-2219 Use a proper cast in unwrap() method in AnalyzerReferenc…
Browse files Browse the repository at this point in the history
…e implementations

This prevents ClassCastException to happen in places where there does
not seem to be a cast.
  • Loading branch information
yrodiere authored and Sanne committed Dec 19, 2016
1 parent e5545cd commit 13656d1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Expand Up @@ -37,9 +37,8 @@ public <T extends AnalyzerReference> boolean is(Class<T> analyzerType) {
}

@Override
@SuppressWarnings("unchecked")
public <T extends AnalyzerReference> T unwrap(Class<T> analyzerType) {
return (T) this;
return analyzerType.cast( this );
}

@Override
Expand Down
Expand Up @@ -39,9 +39,8 @@ public <T extends AnalyzerReference> boolean is(Class<T> analyzerType) {
}

@Override
@SuppressWarnings("unchecked")
public <T extends AnalyzerReference> T unwrap(Class<T> analyzerType) {
return (T) this;
return analyzerType.cast( this );
}

@Override
Expand Down
Expand Up @@ -48,21 +48,20 @@ else if ( RemoteAnalyzerReference.class.isAssignableFrom( analyzerType ) ) {
}

@Override
@SuppressWarnings("unchecked")
public <T extends AnalyzerReference> T unwrap(Class<T> analyzerType) {
if ( LuceneAnalyzerReference.class.isAssignableFrom( analyzerType ) ) {
if ( !( scopedAnalyzer instanceof ScopedLuceneAnalyzer ) ) {
throw log.scopedAnalyzerIsNotLucene( scopedAnalyzer );
}
return (T) new LuceneAnalyzerReference( (ScopedLuceneAnalyzer) scopedAnalyzer );
return analyzerType.cast( new LuceneAnalyzerReference( (ScopedLuceneAnalyzer) scopedAnalyzer ) );
}
else if ( RemoteAnalyzerReference.class.isAssignableFrom( analyzerType ) ) {
if ( !( scopedAnalyzer instanceof ScopedRemoteAnalyzer ) ) {
throw log.scopedAnalyzerIsNotRemote( scopedAnalyzer );
}
return (T) new RemoteAnalyzerReference( (ScopedRemoteAnalyzer) scopedAnalyzer );
return analyzerType.cast( new RemoteAnalyzerReference( (ScopedRemoteAnalyzer) scopedAnalyzer ) );
}
return (T) this;
return analyzerType.cast( this );
}

@Override
Expand Down

0 comments on commit 13656d1

Please sign in to comment.