protected void intializeCollection ( final String annotationType ) { final Field field = getUnderlyingField ( ) ; final Object callerArguments = containingObject ; try { if ( field . get ( containingObject ) == null ) { field . set ( callerArguments , field . getType ( ) . newInstance ( ) ) ; } } catch ( final Exception ex ) { // If we can't instantiate the collection, try falling back to Note: I assume this catches Exception to // handle the case where the type is not instantiable try { field . set ( callerArguments , new ArrayList <> ( ) ) ; } catch ( final IllegalArgumentException e ) { throw new CommandLineException . CommandLineParserInternalException ( String . format ( "Collection member %s of type %s must be explicitly initialized. " + "It cannot be constructed or auto-initialized with ArrayList." , field . getName ( ) , annotationType ) ) ; } catch ( final IllegalAccessException e ) { throw new CommandLineException . ShouldNeverReachHereException ( "We should not have reached here because we set accessible to true" , e ) ; } } }
Initialize a collection value for this field . If the collection can t be instantiated directly because its the underlying type is not a concrete type an attempt assign an ArrayList will be made .