@Test public void readySystemPropertyWithValueSetButParsingError() { System.setProperty(TEST_PROPERTY, "VALUE"); Integer result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, Integer::parseInt); assertEquals(DEFAULT_VALUE, result, 0); result = PropertyUtil.readSystemProperty(TEST_PROPERTY, null, Integer::parseInt); assertNull(result); }
public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } }
PropertyUtil { public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } } }
PropertyUtil { public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } } private  PropertyUtil(); }
PropertyUtil { public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } } private  PropertyUtil(); static T readSystemProperty(String propertyName,
                                                                T defaultValue,
                                                                PropertyParser<T, E> parser); }
PropertyUtil { public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } } private  PropertyUtil(); static T readSystemProperty(String propertyName,
                                                                T defaultValue,
                                                                PropertyParser<T, E> parser);  }