@ SuppressWarnings ( "ProhibitedExceptionDeclared" ) @ PostConstruct public void init ( ) throws Exception { final String configFileLocation = getConfigFileLocation ( ) ; T fileConfig = getEmptyConfig ( ) ; boolean fileExists = false ; log . info ( "Using {} as config file location" , configFileLocation ) ; try ( Reader reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( configFileLocation ) , "UTF-8" ) ) ) { fileConfig = mapper . readValue ( reader , getConfigClass ( ) ) ; if ( fileConfig instanceof PasswordsConfig < ? > ) { fileConfig = ( ( PasswordsConfig < T > ) fileConfig ) . withDecryptedPasswords ( textEncryptor ) ; } fileExists = true ; } catch ( final FileNotFoundException e ) { log . warn ( "Config file not found, using empty configuration object" ) ; } catch ( final IOException e ) { log . error ( "Error reading config file at {}" , configFileLocation ) ; log . error ( "Recording stack trace" , e ) ; // throw this so we don't continue to start the webapp throw new IllegalStateException ( "Could not initialize configuration" , e ) ; } if ( StringUtils . isNotBlank ( defaultConfigFile ) ) { try ( InputStream defaultConfigInputStream = getClass ( ) . getResourceAsStream ( defaultConfigFile ) ) { if ( defaultConfigInputStream != null ) { final T defaultConfig = mapper . readValue ( defaultConfigInputStream , getConfigClass ( ) ) ; fileConfig = fileConfig . merge ( defaultConfig ) ; if ( ! fileExists ) { fileConfig = generateDefaultLogin ( fileConfig ) ; try { writeOutConfigFile ( fileConfig , configFileLocation ) ; } catch ( final IOException e ) { throw new IllegalStateException ( "Could not initialize configuration" , e ) ; } } } } catch ( final IOException e ) { log . error ( "Error reading default config file" , e ) ; // throw this so we don't continue to start the webapp throw new IllegalStateException ( "Could not initialize configuration" , e ) ; } } try { fileConfig . basicValidate ( "Root" ) ; } catch ( final ConfigException e ) { log . error ( "Config validation failed in " + e ) ; throw new IllegalStateException ( "Could not initialize configuration" , e ) ; } config . set ( fileConfig ) ; postInitialise ( getConfig ( ) ) ; }
Exception thrown by method in library