@@ -168,21 +168,23 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi
168
168
// Classname is defined.
169
169
170
170
// Probe class
171
- Class <?> clazz = null ;
171
+ final Class <?> untypedClazz ;
172
172
try {
173
- clazz = Class .forName (className );
173
+ untypedClazz = Class .forName (className );
174
174
175
175
} catch (ClassNotFoundException e ) {
176
176
LOG .error (String .format ("Lucene index: analyzer class %s not found. (%s)" , className , e .getMessage ()));
177
177
return null ;
178
178
}
179
179
180
180
// CHeck if class is an Analyzer
181
- if (!Analyzer .class .isAssignableFrom (clazz )) {
181
+ if (!Analyzer .class .isAssignableFrom (untypedClazz )) {
182
182
LOG .error (String .format ("Lucene index: analyzer class has to be a subclass of %s" , Analyzer .class .getName ()));
183
183
return null ;
184
184
}
185
185
186
+ final Class <? extends Analyzer > clazz = (Class <? extends Analyzer >) untypedClazz ;
187
+
186
188
// Get list of parameters
187
189
List <KeyTypedValue <?>> cParams ;
188
190
try {
@@ -216,7 +218,7 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi
216
218
newAnalyzer = createInstance (clazz , cParamClasses , cParamValues , false );
217
219
218
220
} else {
219
- // Either no parameters have been provided or more than one parameter
221
+ // Either no parameters have been provided, or more than one parameter
220
222
221
223
// Extend arrays with (default) Version object info, add to front.
222
224
Class <?>[] vcParamClasses = addVersionToClasses (cParamClasses );
@@ -252,7 +254,7 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi
252
254
* @param warnOnError true if an error should be treated as a warning
253
255
* @return The lucene analyzer
254
256
*/
255
- private static Analyzer createInstance (final Class <? > clazz , final Class <?>[] vcParamClasses ,
257
+ static < T extends Analyzer > T createInstance (final Class <T > clazz , final Class <?>[] vcParamClasses ,
256
258
final Object [] vcParamValues , final boolean warnOnError ) {
257
259
258
260
final String className = clazz .getName ();
@@ -267,7 +269,7 @@ private static Analyzer createInstance(final Class<?> clazz, final Class<?>[] vc
267
269
if (LOG .isDebugEnabled ()) {
268
270
LOG .debug (String .format ("Using analyzer %s" , className ));
269
271
}
270
- return (Analyzer ) methodHandle .invokeWithArguments (vcParamValues );
272
+ return (T ) methodHandle .invokeWithArguments (vcParamValues );
271
273
} catch (final NoSuchMethodException e ) {
272
274
final String message = String .format ("Could not find matching analyzer class constructor %s: %s" , className , e .getMessage ());
273
275
if (warnOnError ) {
@@ -318,7 +320,7 @@ private static Class<?>[] addVersionToClasses(final Class<?>[] cParamClasses) {
318
320
* @return List of triples key-value-valueType
319
321
* @throws org.exist.indexing.lucene.AnalyzerConfig.ParameterException
320
322
*/
321
- private static List <KeyTypedValue <?>> getAllConstructorParameters (Element config ) throws ParameterException {
323
+ static List <KeyTypedValue <?>> getAllConstructorParameters (Element config ) throws ParameterException {
322
324
final List <KeyTypedValue <?>> parameters = new ArrayList <>();
323
325
final NodeList params = config .getElementsByTagNameNS (CollectionConfiguration .NAMESPACE , PARAM_ELEMENT_NAME );
324
326
@@ -455,29 +457,43 @@ static KeyTypedValue<?> getConstructorParameter(final Element param) throws Para
455
457
}
456
458
457
459
case "java.lang.Integer" :
458
- case "int" :
459
-
460
460
if (value == null ) {
461
461
throw new ParameterException ("The 'value' attribute must exist and must contain an integer value." );
462
462
}
463
-
464
463
try {
465
464
final Integer n = Integer .parseInt (value );
466
465
parameter = new KeyTypedValue <>(name , n , Integer .class );
467
- } catch (NumberFormatException ex ) {
466
+ } catch (final NumberFormatException ex ) {
468
467
LOG .error (String .format ("Value %s could not be converted to an integer. %s" , value , ex .getMessage ()));
469
468
}
470
469
break ;
471
470
471
+ case "int" :
472
+ if (value == null ) {
473
+ throw new ParameterException ("The 'value' attribute must exist and must contain an int value." );
474
+ }
475
+ try {
476
+ final Integer n = Integer .parseInt (value );
477
+ parameter = new KeyTypedValue <>(name , n .intValue (), int .class );
478
+ } catch (final NumberFormatException ex ) {
479
+ LOG .error (String .format ("Value %s could not be converted to an int. %s" , value , ex .getMessage ()));
480
+ }
481
+ break ;
482
+
472
483
case "java.lang.Boolean" :
473
- case "boolean" :
484
+ if (value == null ) {
485
+ throw new ParameterException ("The 'value' attribute must exist and must contain a Boolean value." );
486
+ }
487
+ final Boolean b1 = Boolean .parseBoolean (value );
488
+ parameter = new KeyTypedValue <>(name , b1 , Boolean .class );
489
+ break ;
474
490
491
+ case "boolean" :
475
492
if (value == null ) {
476
493
throw new ParameterException ("The 'value' attribute must exist and must contain a boolean value." );
477
494
}
478
-
479
- final boolean b = Boolean .parseBoolean (value );
480
- parameter = new KeyTypedValue <>(name , b , boolean .class );
495
+ final Boolean b2 = Boolean .parseBoolean (value );
496
+ parameter = new KeyTypedValue <>(name , b2 .booleanValue (), boolean .class );
481
497
break ;
482
498
483
499
default :
0 commit comments